Journal Contact

A Fix For Slow Sendmail On Ubuntu

I currently host a majority of my websites on a DigitalOcean VPS. For the most part it's been a great experience, and easy on my wallet. One thing I noticed however, was trying to use PHP's sendmail function.

If you just install it via apt-get, you'll likely notice that sending mail is painfully slow. There is a quick fix for this fortunately, and I'm going to show you how. First of all, if you don't have sendmail installed, you'll want to do that. Pretty easy, once you're SSH'd into your server, execute the following command:

apt-get install sendmail

Great, we now have the sendmail module installed. Now, we need to configure our hosts file, just to make sure our entry is correct. If you don't know your host name, just run the command hostname, and it will return it. Now we need to edit our hosts file. The quickest way is to use a command line text editor like nano, so let's do that.

nano /etc/hosts

There should be an entry for your localhost. Edit the line so it resembles this, but using your own hostname.       localhost localhost.localdomain yourhostnamehere

Press Control+o, then enter, and finally Control+x to exit nano. Now issue the following command and answer 'Y' to everything:

sendmail config

And for good measure, restart apache:

service apache2 restart

After that, your sendmail function should work much faster. Questions or comments? I'm @syropian on Twitter.

comments powered by Disqus