David Hurst

PHP/MySQL, REALbasic, Javascript Developer

PHP mail() and ssmtp on Debian Linux

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 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.

Now, if your SMTP server requires authentication, you will need the -au -ap and possibly -am flags below, otherwise you can ignore them.

sendmail_path = /usr/sbin/ssmtp -t -i -au username -ap password -am LOGIN

PHP requires the -t and -i flags. The rest is for SMTP authentication.

Save your php.ini and restart Apache (probably /etc/init.d/apache2 restart). Your mail() function should now work.

Enjoy.

RSS 2.0 | Trackback | Comment

4 Responses to “PHP mail() and ssmtp on Debian Linux”


  1. Nice on on the the guide.. so much handier than messing around with sendmail and postfix installs.

  2. Luciano

    This just saved me a lot of time, thanks!


  3. Hey David,

    Awesome tutorial, saved a load of time, and ssmtp works very fast and its really recommend. Was using sendmail and was really slowwwww, like 2mins or a timeout before sending a few KB of mail.

    Nice, and thanks, I’ll print this for personal reference if you dont mind.


  4. Oliver,

    Glad I could be of help. Feel free to print and save.

    Regards,

    David

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>