Sendmail alternative – postfix on ubuntu (when PHP doesn’t send emails) in a few easy steps

Imagine you have your new shiny Ubuntu server. You installed your php, apache & mysql and everything seems fine until… you realised your system doesn’t  send emails.

If there is a problem – there must be a solution! In our case it’s either install good (… not so in fact) sendmail or postfix.

We decided to install postifix:

> sudo apt-get install postfix

Pick the correct option in a nice interface (for the web site it’s normally Internet)

choose Internet in postfix install

choose Internet in postfix install









Now it’s all “almost” working ;)You also have to go and change php.ini to pick your new mail sending program.

* Please note: since I am using Apache MPM_Worker on my local server – my PHP is working as a FastCGI module. So, my php.ini is located here: /etc/php5/cgi/php.ini
on a default installation of Apache it’s most likely here:  /etc/php5/apache2/php.ini

Check where is your new “sendmail” is located:
> which sendmail

Good! Now change php.ini – find following string in it:

and add / edit following line below (don’t forget to replace email from field – just in case):

sendmail_path = /usr/sbin/sendmail -t -i -f

Restart Apache:

> sudo service apache2 restart


PS: more info can be found here:

One useful hint – To configure postfix, run the following command:
sudo dpkg-reconfigure postfix


To test if it’s working ok:

> apt-get install mailutils

echo 'this is a test mesage body' | mail -s test_email_header

And test in PHP document on the server:

// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
if (mail('', 'My Subject', $message)){
echo "ALL GOOD";
echo "Sending Failed";


Posted on March 28, 2013 at 12:20 by arte · Permalink
In: Fighting the system, Linux, Ubuntu · Tagged with: , , , ,

2 Responses

Subscribe to comments via RSS

  1. Written by Felipe
    on December 12, 2013 at 18:58

    Hi There! I really appreciate your help but I have a ask: What to put on postfix config?


  2. Written by arte
    on December 12, 2013 at 21:09

    I don’t normally change anything. Works like this – no problems.

Subscribe to comments via RSS

Leave a Reply