Checking if PHP/WordPress can send mails

WordPress has grown from a blogging platform to become a highly efficient CMS. Chances are high that you are using a contact form on your WordPress. Imagine if a prospective client fills up your contact form but WordPress fails to send you an email notification!

If you are facing problems like these, you should do the following:

First check if PHP-scripts can send emails

php -a
mail ('you@example.com', "Test Postfix", "Test mail from postfix");
exit ();

Note: if after running php -a, you get "Interactive mode enabled" message but no php> prompt, then your PHP is not compiled with readline support. If its working nice, you will get only "Interactive mode" message with php> prompt.

You can still run test though. Just create a testmail.php with following lines of codes:

<?php
    mail ('you@example.com', "Test Postfix", "Test mail from postfix");
?>

and run it on your server with php -f testmail.php command. If you can’t see any email form PHP, then that means its PHP’s fault.

Check value of sendmail_path in php.ini config. If its wrong, fix it and run above test again.

If PHP can send mails, but WordPress cannot, its better to test WordPress.

Check if WordPress can send emails

Testing WordPress is easy. You can do it using this plugin. I know that plugin is not updated from 2 years but I tested it with WordPress 3.4 without any issue. Its a simple plugin so chances are very less that it will break in future as well! 😉

Now if in your test you can send emails but still facing issues with contact form, its better to check your plugins then. Mostly likely it will be some coding issue.

32 thoughts on “Checking if PHP/WordPress can send mails

    1. Its a path to sendmail program on your server.

      On Linux, just run command:

      which sendmail
      

      It will show you path like:

      /usr/sbin/sendmail
      

      In my case, value of “sendmail_path” is “/usr/sbin/sendmail -t -i -f www@my.domain.com“. This is system default as I never needed to change it.

  1. Thanks for your guides

    Im in the process of setting my own ubuntu box up with WordPress and postfix.

    It sends okay with the command

    echo "Test from Postfix" | mail -s "Test" test@domain.com

    It also sends okay via the php commands you mentioned above. However it doesnt send via wordpress. Using the plugin it goes but never gets delivered. mail.log shows no entry.

    Any ideas where to look?

    1. Please check error.log file for WordPress. Most likely it will be available at /var/www/domain.com/logs/error.log.

      Also, you can disable other WordPress plugins and check if WordPress can send emails.

  2. Thanks. I found the issue in the end. In the apache logs it was pointing to the wrong path for sendmail. Was missing the / before /usr/

    1. I can send and receive the email using echo “Test from Postfix” | mail -s “Test” test@domain.com but when I tried using “check email” plugin in WordPress, it didn’t work.

  3. Jul 22 16:56:12 smith postfix/error[19857]: BC723A061: to=, relay=none, delay=0.01, delays=0/0/0/0, dsn=5.0.0, status=bounced (gmx.de)

    POSTFIX
    # postconf -d | grep mail_version
    mail_version = 2.7.1
    milter_macro_v = $mail_name $mail_version

  4. Sorry, this is too advanced for me. Could you please give me a brief description of how to find that PHP snippet or how to “run” it? Do I have to type it in somewhere or do I find it in my wordpress files?

  5. Thanks for the troubleshooting steps. I have followed them
    Check point 1 – no issues with PHP setting e-mail goes
    Checkpoint 2 – the plugin says “The test email has been sent by WordPress” but actually e-mail is not received. It looks all weird. Any clues on what’s happening to me?

    1. Check postfix logs and wordpress error logs. Most likely its an issue with WordPress.

      Or you might have added your test email address' domain in postfix's mydestination list.

  6. I used check mail today with WordPress 3.5.1 and it still works great. I was able to fix some email issues in seconds.

    Great post by the way.

  7. Thanks a lot .. it helped me a lot .. In ubuntu we just have to type sudo apt-get install sendmail and then you can send email from wordpress.

  8. Hello guys,

    My name is Paula, I’m venturing on WordPress and I am creating my own website. I take this opportunity to apologize for my English because I am Brazilian and my English is not perfect yet. But I think you will understand me and help me 🙂

    I bought a theme on ThemeForest, i’m installation normally, but the contact form is having problems with the variables used.

    Let me explain: the form has 3 fields (Name , Email and Message), the visitor fills out and submits, however, get only the name and email address of the visitor, but the message that I do not get visitor wrote.

    I am in contact with the support of the theme for almost 10 days and are not solving. Perhaps because of problems with their language (french).

    I’m not a programmer, but I decided the little I know, I see clearly wrong in the formmail code (refer to fields / variables used).

    See if you can help me solve:

    – Send_mail.php : http://pastebin.com/MMjEnAy0
    – Contact.php : http://pastebin.com/dd1Km2Hg

    If you need any more information or file, I can post too.

    Attached pdf file showing how am receiving emails in my inbox.

    Well, the file “send_mail.php” ‘m finding strange line 6 ( $ msg = ” ). Such is not the variable that should be written with any value or different?

    Sorry, as I said, I’m not a programmer, I went by instinct and curiosity even. If you can help me, I am sooooo thankful.

    Thanks in advance to all.

    Paula Viegas

    1. Ready, is now working! Just swapped $ _REQUEST [Message] to $ _REQUEST [message] and problem solved.

  9. Hi there;

    This certainly seemed like the best place to post my issue and wondered if you could point me in the right direction.

    I have an odd scenario, we run a nginx setup with wordpress, and woocommerce. Now most of our emails are sent out to users (60%), however, it doesn’t matter which plugin, or system that is engaged, about 40% of them fail (they are not sent to junk mail or similar, they just don’t arrive at all).

    WordPress’s sendmail function certainly works, and I cannot see a pattern to the issue, so wondered if you had any suggestions as to what I might look out for, as it has totally perplexed me (I’ve even checked blacklist registers etc. which I know it couldn’t really be).

    Many thanks for any and all suggestions in advance

    1. You should also debug amavis if you have it running on the server.

      We had a similar problem where 80% of emails would be sent and it bugged us for months until we discovered amavis was the culprit. We removed it from the linux server and the problem went away.

      1. Thanks for adding your points. 🙂

        We also use amavis (without any issue) and if that is creating any issue, postfix mail.log will have entries about it.

  10. Hi,
    I try to send mail from my wordpress site, it seems like both mail() and wp_mail() returns true, but the mails don’t arrive. Tried with a test.php from the same server, and still mail() gets true, but no email arrives to my account. I tried the echo “Test from Postfix” | mail -s “Test1” email from terminal and it works.

    I have no idea at this point. Checked the sendmail path, and smtp settings, and they seems to be as supposed.

    Do you have some suggestions?

    Thanks,
    Katalin

    1. I also checked the php.ini configurations for terminal and php with and php -i and the options smtp, sendmail_path, sendmail_from, smtp_port are the same. Why does it work from terminal but not from .php?

Comments are closed on this article.
Please use our free support forum for support and discussions.