DEV Community

Cover image for Php Send Mail
Ashwin K Shenoy
Ashwin K Shenoy

Posted on

Php Send Mail

I agree that many newbies don't use Php nowadays. But this post is for noobs like me at Php :)

After installing Sendmail on ubuntu server 14.04 / 16.04, I tried sending mail from my PHP script and it was painfully slow. I thought I had not configured Apache / Nginx properly. Me being a noob at this tried to delete the snapshot and reinstalled with ubuntu 14.04 (earlier one being ubuntu 16). Still, the issue persisted. After a lot of googling I kind of figured a solution.

Initially determine the hostname of your server by typing:


This will reveal your hostname.

Then go to /etc/hosts

sudo vi /etc/hosts

Modify the line with IP to read as:    localhost localhost.localdomain ashwin

(where “ashwin” is my server’s hostname, you should add your server’s hostname — duh!)

Finally, I ran

sudo sendmailconfig

Answer Y to all the questions asked to rebuild/reload Sendmail configuration.

That’s it, Send Mail started working!

Hope this helps for people who struggled with installing a new server in Digital Ocean / AWS and trying to send mail!

That’s the end of this blog post!
Thanks for reading! If you like it, please hit ♥️

Top comments (0)