Saturday, September 29, 2018

linux - Troubleshooting PHP Mail




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?


Answer



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.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...