Getting the PHP mail() Function (sendmail) to Work on Ubuntu 14.04

Alright, let me start off by saying that I know there are better and more professional solutions for sending email on web servers. But sometimes you just want to use PHP's mail() function to get it done quickly and simply.

Here are the steps I took to get sendmail working on my Ubuntu server.

1) Install sendmail

Sendmail might already be installed, but just in case, enter this into the server terminal:

2) Configure sendmail

Enter the following command into the terminal and type "Y" for each question it asks:

3) Edit hosts file

Time to edit your server's hosts file, access it by entering the following command into the terminal:

Add the following line to the top of the file and save it:

Comment out any duplicate lines that already existed.

4) Restart apache

Let's restart your server just for good measure. At this point emails sent via PHP's mail() function should be sending successfully and without much delay.

I hope this solved the problem for you. I've followed this exact procedure on three different Ubuntu 14.04 LTS servers and it has worked for each one.

Posted on August 14th, 2015