Let's install our program:
sudo apt-get install ssmtp
Then we need to edit it's configuration file:
sudo nano /etc/ssmtp/ssmtp.conf
1. The configuration to use Gmail's smtp server is:
AuthUser= is the username which authenticates
AuthPass= is the password for the user above
FromLineOverride= is needed to allow the user to specify their own From: address (Gmail does not allow the user to specify their own From: address)
mailhub= is the smtp server through which we are going to send the emails. the port is optionally needed.
UseSTARTTLS= is to make a secure connection. Gmail needs it.
rewriteDomain= where will the mail seem to come from
hostname= the full hostname of the machine
2. To send email by function mail() in php using this external server
Usually the setings above may already work for the function mail() in php, but if it doesn't you need to set sendmail_path in php.ini:
The php.ini file usually is located in php's folder
sudo nano /etc/php5/apache2/php.ini
Press CTRL+W and enter sendmail_path. This is the find function in nano editor.
Delete the line where is sendmail_path (CTRL+K) and paste the following:
sendmail_path = /usr/sbin/ssmtp
a. To verify if the server is sending emails, send a test email:
The prompt will expect to enter something.
Subject: test email
b. You can check if the email are sent by running the following in a second terminal (ALT+F2):
tail -f /var/log/mail.log
This will "catch" live the emails that are sent. Another method to see the emails that were already been sent:
sudo nano /var/log/mail.log
Resources: tombuntu.com, tuxnetworks.blogspot.com,