In webdevelopment projects are first of all developed locally before the go live. Is the mail()-function used during the development with PHP, then it’s necessary to be able to send e-mails from localhost. This blogpost shows how to send e-mails from localhost using an ubuntu-system with Apache-webserver.
In a first step SSMTP needs to be installed. That is possible with the following Shell-command:
sudo apt-get install ssmpt
Then find out where SSMTP is installed:
Configure the ‘ssmpt.conf’-file
Change to the directory ssmpt and open up the ‘ssmpt.conf’-file for instance with the nano-texteditor. Configure the file like that:
# Config file for sSMTP sendmail
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
# Where will the mail seem to come from?
# The full hostname
# 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
In order to set the lines for ‘mailhub’ or ‘STARTTLS’ and ‘TLS’ correct you may check the settings in your e-mail-client, for example Thunderbird, to get them right.
Set ‘sendmail_path’ correct
Then the line ‘sendmail_path’ needs to be set correct in your ‘php.ini’-file:
sendmail_path = /usr/sbin/ssmtp -t
Most of the time you’ll find the ‘php.ini’-file under the path ‘/etc/php5/apache2′. Last but not least restart the webserver:
sudo service apache2 restart