Checking if PHP/WordPress can send mails

NGinx

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.