This seems to be an evergreen topic for me. Every day I keep discovering options that have control over the outgoing emails. I hope to log every detail here assuming that it will help someone some day.

So, if your scripting language is PHP, and uses mail() function to send mails, read on.

# Agent 1:

Incorrect TO: address. Please check whether your recipient email address is correctly entered.

# Agent 2:

Incorrect FROM address. Yeah. These days, it is indeed possible to send a mail to any tom, dick and harry from email addresses like bush@whitehouse.com or pamela@anderson.com. But not every server likes that. SPAM protection is in and hence servers try to check the validity of the entered FROM address. If your FROM address is in an incorrect format or is some non-existant address, chances are that your mail() function would not work.

# Agent 3:

So, The TO: address and the FROM: address are correct. Mail() still does not work. If you have access to the function call in the php script that says

mail($to,$subject,$message,$from);

Try assigning the returned value to a variable and display it. Also, you could turn on error_reporting and see whether the mail() function throws up any error.

Chances are that, PHP.INI file wasn’t configured to contain the PATH to the sendmail binary or SMTP address. If you are not sure about this, do a phpinfo on the server to find out the configuration details. If the configuration is correct, check whether your sendmail allows relaying.

# Agent 4:

The PHP software is configured to contact the SMTP server or the SENDMAIL binary. Sendmail allows relaying. But still, mails don’t go out. What do we do now?

Check the sendmail error log. See whether you get a message like “Deferred”. This could probably mean that your sendmail is listening only to its localip. If this is the case, then you would be able to send mails only to and from localhost.

Open the /etc/mail/sendmail.mc file and search for the text ‘DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA’)’.

If this text is not commented out (comment character is dnl here), add a ‘dnl’ to the beginning. Then, execute the following commands.

# cd /etc/mail
# m4 sendmail.mc > sendmail.cf
# /sbin/service sendmail restart

Make sure you are logged in as root user to do the above. Once this is done, your mails should work!! If it still doesn’t, …….. well, I haven’t found a similar case. Lemme know if it doesn’t.

Advertisements