CentOS – SendMail issue

If you are hosting your PHP using CentOS in Azure, the chances are high that you will hit this issue. Basically, if your PHP code uses mail() function to send mail for notifications, you might find that it is not sending the mails as you anticipated it to. It is because, PHP mail uses sendmail to send its mail. So ensure that you have sendmail installed.

sudo yum install sendmail  

Also install the mail client so that you can be sure that the mail is flying well.

sudo yum install mailx  

When you issue the following command, you will get in a writing mode. You can write a small test letter. When you are done, type . (period) and hit enter. It should say EOT and your mail should reach you.

mail -s "Test Mail" your-emai@gmail.com  

If you don’t receive the mail, it means there is something wrong. In the folder mentioned below you can find your mails undelivered.

sudo ls -la /var/spool/clientmqueue  

You can do a cat on them and find the error message. In my CentOS 7 install image (on Azure), I found the following error:

MDeferred: Connection refused by []  

Clearly, there is something missing! The mail is not getting sent, because it is actively getting refused by the local server. Open the file, and modify it so that it has in one of the lines.

sudo vi /etc/mail/local-host-names  

Something like this should do…

# local-host-names - include all aliases for your machine here.  

Restart your service.

sudo service sendmail restart  

Check your mail, and you should be able to find your stuck mails being delivered (most likely in your spam folder ;-).

Hope this helps!

Rahul Soni

⌘⌘ Entrepreneur. Author. Geek. ⌘⌘

Kolkata, India

Subscribe to Attosol

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!