Skip to Content
All memories

Email with sSMTP and PHP

 — #php#sendmail

Although postfix seems like most popular forworking with email, it would be an overkill if we need to just send emails from php at least while developing in a local server.

A very simple and lightweight package ssmtp comes into play here. It will use any smtp server to send outbound emails. You can 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):

mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=<YOUR-EMAIL>@gmail.com
AuthPass=<YOUR-PASSWORD>

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

ssmtp should create symlink for /usr/sbin/sendmail, which correctly points to ssmtp. If not be sure to check that your php.ini has correct sendmail_path. It should read as:

sendmail_path = /usr/sbin/sendmail -t

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