Question

This question already has an answer here:

How can I check a problem with mail being sent on my server? I run a simple test:

if(mail($to, $subject, $message)) {
echo 'Mail Sent';
}

which the test outputs the text; but, no mail ever arrives.

How can I go about tracking down the issue?

Was it helpful?

Solution

That is quite a long story. A few bullet points (Assuming that mail() returns true and there are no errors in the error log) :

  • Does the sender address ("From") belong to a domain on your server? If not, make it so.
  • Is your server on a blacklist (e.g. check IP on spamhaus.org)? This is a remote possibility with shared hosting.
  • Are mails filtered by a spam filter? Open an account with a freemailer that has a spam folder and find out. Also, try sending mail to an address without a spam filter.
  • Do you possibly need the fifth parameter "-f" of mail() to add a sender address? (See mail() command in the PHP manual)
  • If you have access to log files, check those, of course, as suggested above.
  • Do you check the "from:" address for possible bounce mails ("Returned to sender")? You can also set up a separate "errors-to" address.

For german speakers, I have written a quite exhaustive "what to do" on this issue some time ago. See here.

OTHER TIPS

Following Myles, if you are on a Linux box, do this on the command line:

# echo “Body text.” | mail -s “Hello world” you@example.com

If you don't receive that email, you have a problem with the mail system on that box. That is a different question from the PHP question you asked.

From the PHP manual:

Return Values

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

It is important to note that just because the mail was accepted for delivery, **it 
does NOT mean the mail will actually reach the intended destination**.

Not sure how to take that next step, but that's an important point here.

If all the troubleshooting fails - now assuming that mail() returns false for reasons unknown - switch to a mailing script like PHPMailer that allows you to bypass mail() altogether and connect directly through SMTP, and offers an extensive debug mode. That way, you should be able to either set up a working solution or find the core of the problem.

The first place I'd start is the PHP error log, then your sendmail log. Also try sendmail from the command line and check the PHP configuration to make sure that is setup correctly for sending mail.

Are you working on a live webserver here, or something more along the lines of a personal development sandbox? (Ie, your home machine?) If it's the latter, I can tell you that I've had a lot of problems in the past with my ISP (Cox) filtering my outbound mail ports. (They'll tell you that they don't do that, but I'm certain they do.)

I've also gotten some outbound messages that did make it through get caught up in the Cox mail spool for days before they were delivered to me.

I hope that's helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top