PHP mail() and ssmtp on Debian Linux
borrowed from here
If, like me, you have a dedicated mail server that you want your PHP scripts to use, you may have come across ssmtp. ssmtp is a cut-down MTA that simply sends mail off to another server – ideal for scenarios where you don’t need to receive mail on your web server, but you do want to be able to use the PHP mail() function.
It’s very simple to set up, and it is not, as some have said, impossible to get PHP to use ssmtp. These instructions are for Debian. Should also work with Ubuntu.
- First of all, install ssmtp with apt-get install ssmtp
- Next you need to edit the conf file at /etc/ssmtp/ssmtp.conf. Set the mailhub= line to the address of your SMTP server. Put your hostname on the hostname= line, and put FromLineOverride=YES.
- Now, if your SMTP server requires authentication, you will need the AuthUser, AuthPass and possibly AuthMethod flags below – add these to the bottom of the ssmtp.conf:
- AuthUser=your smtp username here
- AuthPass=your smtp password here
- Now you need to edit your php.ini. On Debian, you will likely find this in /etc/php5/apache2/php.ini – obviously change the directories for the appropriate versions of PHP and Apache on your system. (Quick tip: not sure where a file might be? Type updatedb at the command line, and when that’s finished, locate filename). In your php.ini, find the sendmail_path= line.
- sendmail_path = /usr/sbin/ssmtp -tPHP requires the -t flag.
- Save your php.ini and restart Apache (probably /etc/init.d/apache2 restart). Your mail() function should now work.