Skip to content

Instantly share code, notes, and snippets.

@Fleshgrinder
Last active December 19, 2021 11:06
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fleshgrinder/d641f77121de9fb9180abbb4d9452c49 to your computer and use it in GitHub Desktop.
Save Fleshgrinder/d641f77121de9fb9180abbb4d9452c49 to your computer and use it in GitHub Desktop.
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

root=user@host.name
hostname=host.name
mailhub=smtp.host.name:465
FromLineOverride=YES
AuthUser=username@gmail.com
AuthPass=password
AuthMethod=LOGIN
UseTLS=YES

EOF

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('recipient@host.name', 'Test Mail from PHP', 'This is a test mail sent from PHP.'));

Links

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