How to enable PHP mail function on Ubuntu

I personally use very simple and lightweight package ssmtp. It will use any smtp server to send outbound emails. Install it by running:

sudo apt-get install ssmtp

Then edit /etc/ssmtp/ssmtp.conf file, comment out existing mailhub line and add the following lines (this example is for gmail smtp server):

(Provide your gmail username & password. Of course you can use any other SMTP server).

Now make sure that your php.ini has correct sendmail_path . It should read as:

sendmail_path = /usr/sbin/sendmail -t

( From comments of @dima-l and @omar-sabic : You do not have to specify ssmtp here because the installation should have created a symlink for /usr/sbin/sendmail , which correctly points to ssmtp . Otherwise you have to specify sendmail_path = /usr/sbin/ssmtp -t )

Reload apache and your php should be able to send outgoing emails now.