PHP mail() with MSMTP

PHP mail() made easy without a whole mail delivery system like sendmail or postfix.
Use msmtp http://msmtp.sourceforge.net/
Lightweight easy to install and configure.

Installation for LFS:

# wget http://sourceforge.net/projects/msmtp/files/msmtp/1.4.30/msmtp-1.4.30.tar.bz2
# tar -xvf msmtp-1.4.30.tar.bz2
# cd msmtp-1.4.30
# autoreconf -i
# ./configure --prefix=/usr
# make
# make install

Configuration for non authorized smtp access to your smtp provider:
ie. No username/password not encrypted.

Edit or create /usr/etc/msmtprc

And put the following in it.

# msmtp configuration file
# Set default values for all following accounts.
defaults
tls off
#tls_trust_file /etc/ssl/certs/ca-certificates.crt
#logfile /var/log/maillog/msmtp.log

# The SMTP server of the provider.
account provider
host smtp.example.com
from youremail@example.com
auth off
#user 123456789
#passwordeval gpg -d ~/.msmtp.password.gpg

# Set a default account
account default : provider

You will have to change smtp.example.com with your smtp provider and change youremail@example.com with your own valid email address.

Next you will have to tell php to use msmtp.
Edit /etc/php.ini
Search for the line that starts with:
sendmail_path
uncomment it and/or change the line to this.

sendmail_path = "/usr/bin/msmtp -t"

Restart your httpd to activate the php changes.
Done !

Happy php mail()ing 🙂

Leave a Reply

Your email address will not be published.

+ 55 = 56