apt-get install msmtp
vim /etc/msmtprc
defaults
port 587
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
account YourSMTP
host smtp.foobar.com
from [email protected]
auth on
user baz
password bazS3cr3tpass
account default: YourSMTP
chmod 0600 /etc/msmtprc
chown www-data:www-data /etc/msmtprc
vim /etc/php/7.0/apache2/php.ini
Change the sendmail_path
to: sendmail_path = "/usr/bin/msmtp -C /etc/msmtprc -t -i"
Restart Apache and you're good to go.