sudo apt-get update
sudo apt-get install ssmtp
Check where the binary and the ssmtp.conf file ended up. You’ll need to know the locations for the following steps:
whereis ssmtp
ssmtp: /usr/sbin/ssmtp /etc/ssmtp /usr/share/man/man8/ssmtp.8.gz
Edit /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=your-full-gmail-address
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
# Where will the mail seem to come from?
#rewriteDomain=
# The full hostname
hostname=your-full-gmail-address
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
UseSTARTTLS=YES
AuthUser=your-gmail-username-here
AuthPass=your-gmail-password-here
Edit `/etc/ssmtp/revaliases`
You’ll probably want to set up your local user and root for sedning mail:
root:username@gmail.com:smtp.gmail.com:587
localusername:username@gmail.com:smtp.gmail.com:587
Edit `/etc/php5/apache2/php.ini`
Find the [mail function] configuration line:
it must be look like this:
sendmail_path = /usr/sbin/ssmtp -t
sudo service apache2 restart
$to = 'your@email.com';
$subject = 'the subject';
$message = 'hello world';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'mail has been send';
HAPPY :)