Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Set up sSMTP on Debian as replacement for sendmail and usage with PHP

sSMTP Debian Setup

The sendmail package, which comes preinstalled with many distros, is often simply too much for a simple server that should not receive emails but rather deliver them. The sSMTP package is a lightweight replacement that does not set up regular cronjobs and only reacts if a subsystem actually wants to send a mail.

Uninstall Sendmail

apt-get purge --yes sendmail*

Install sSMTP

apt-get install --yes ssmtp

groupadd mail

dpkg-statoverride --update --add root mail 0640 /etc/ssmtp/revaliases
dpkg-statoverride --update --add root mail 0640 /etc/ssmtp/ssmtp.conf

dpkg-statoverride --update --add root mail 0750 /usr/sbin/ssmtp
chmod g+s /usr/sbin/ssmtp

cat << EOF > /etc/ssmtp/ssmtp.conf
# /etc/ssmtp/ssmtp.conf


Configure PHP

usermod -a -G mail php-user

Change the PHP sendmail configuration in the php.ini file as follows:

sendmail_path = "/usr/sbin/sendmail -t -i"

A simple test script:

#!/usr/bin/env php

var_dump(mb_send_mail('', 'Test Mail from PHP', 'This is a test mail sent from PHP.'));


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment