Drupal not Sending Email? Let's Debug it!

So your Drupal site doesn't seem to be sending any email. Bummer. Here are some steps to debug the issue you're having.

Step 0: Check your spam folder

As always with email related issues, step 0 should be to check the junk folder. You can save yourself a lot of debugging.

Step 1: Test email outside of Drupal

To do this, create a small PHP script with this in it:

&lt;?php<br />
        $to = &quot;your@email.com&quot;; // REPLACE<br />
        $subject = &quot;Test mail&quot;;<br />
        $message = &quot;Hello! This is a simple email message.&quot;;<br />
        $from = &quot;noreply@eample.com&quot;;<br />
        $headers = &quot;From:&quot; . $from;<br />
        mail($to,$subject,$message,$headers);<br />
        echo &quot;Mail Sent.&quot;;

Make sure to replace the "to" address, save it as mail.php, and run it using "php mail.php". If you get email from that, then the problem is specific to Drupal, and if not, then your server isn't sending email at all and you should contact your host.

Step 2: Test regular Drupal email

Maybe your issue is with one specific email Drupal is trying to send, and not that Drupal can't send email at all. The easiest way to test this is to go to /user/password to send yourself a password reset email. If you get email from that, then whatever feature you're NOT getting email from is probably buggy or not running as you would expect, and you'll have to dig into the code for it. Or if you don't get email from that, then move on.

Step 3: Check the logs

There are a couple places to look for error messages. The first is watchdog which (in Drupal 7) is available at /admin/reports/dblog.

If you don't see anything interesting there, then check the server mail logs. These are usually in /var/log, and typically named mail.log. Run "tail -f /var/log/mail.log" to display the auto-updated end of the file, and then on the site, trigger whatever it is that should be sending your email to see if anything pops up in the auto-updated error output.

Step 4: Check the mail queue

If you're running postfix (you probably are) then you can do this by running "mailq" and looking at the output. If you see anything besides "Mail queue is empty" then it's possibly you have an email stuck in the queue. If so, see if it has any information about why it's stuck or perhaps a link to view error information. This can help a lot in debugging, and may give you some information to take to your web hosting provider.

Step 5: Clear any emails stuck in the queue

Sometimes just deleting the stuck email can get things rolling again. Try running "postsuper -d ALL" to clear the queue (be careful, because this really does clear the entire queue) and then retrying your email sending.

Step 6: Resort to external SMTP if possible

If all else fails and you just want to get things working, you can always install the SMTP module and set it to use gmail as your SMTP server to avoid whatever on your server is messing things up. This won't work for all sites (especially ones that send a lot of email) but for most sites it can be a relatively painless quick fix.

Step 7: Contact your web host

If you're really stuck, it can't hurt to ask if your web host has any ideas. Maybe this is a problem other users are having or that they've seen before. 

Share This