This article is over two years old. Life moves quickly, and thus there is a good chance any references, recommendations, or opinions in this content are out of date. Make sure to verify any information independently.

Fixing PHP mail() on Ubuntu

Published 08 April 2011

I’m still settling into the new Rackspace Cloud Server, and I just solved a problem I was trying to fix for the last two days. And all I had to do was change three characters in an .ini file.

On my server I’m running Ubuntu 10.04 Lucid LTS. I had everything working – MySQL, PHP, Apache… The only thing that wasn’t working properly was sendmail. It would send, but after it hung for a minute and 25 seconds (I timed it). This was bad – to comment in WordPress, the person would have to wait for a minute-and-a-half after they click “submit” before it would finally go.

It took me two solid days of searching through forum threads and blog posts before I finally found the answer. I probably lost a bit of hair as well.

In the end, the fix was as simple as removing the -i at the end of the sendmail_path variable in my php.ini.

How To Do That

First, find your PHP.ini file’s location. For me it’s under /etc/php5/apache2/php.ini. You can find this by using the phpinfo() function.

I use nano, but you could use VIM or another editor of your choosing. I simply opened my PHP.ini file, and found the sendmail_path line (which, for me, is on line 1047). Just search for a line that starts with sendmail_path.

Then, change the line so it says: sendmail_path = /usr/sbin/sendmail -t.