Enabling PHP mail() in Debian easily and quickly
I've run into a problem more than once where the mail() function in PHP didn't work. Unlike with a Windows deployment, you can't simply set an SMTP server in the php.ini file; you must set a value for the sendmail_path.
If you're running a mail server like Sendmail or Postfix alongside your web server, this is no big deal. But for the rest of us, do we really need a big beefy MTA just to mail-enable PHP?
No, we don't! I found a very simple way to get PHP sending mail without setting up a full-blown MTA, using sSMTP. sSMTP is not a running daemon, does not have a queue, and it cannot accept mail for delivery -- all it does is relay a message immediately and directly to the SMTP server it's configured to use. For most PHP users, this is a perfect solution.
- First, install ssmtp
apt-get install ssmtp
- Next, edit the configuration file at /etc/ssmtp/ssmtp.conf.
- Set the mailhub= line to the name or address of your SMTP server
- Set the hostname= line to the actual host name of this server
- Set FromLineOverride=YES, otherwise, the From: set in any PHP application will be ignored
- If your SMTP server requires authentication, then
- Set AuthUser= to the SMTP username
- Set AuthPass= to the correspnding password
- Set AuthMethod=LOGIN
- Now you need to configure PHP. In Debian, it's recommended to create new .ini files inside of /etc/php5/conf.d instead of editing the php.ini file directly. Create a mail.ini file inside /etc/php5/conf.d, and add the following line:
sendmail_path = /usr/sbin/ssmtp -t
PHP requires the -t option, and the usual -i option is ignored
- Save the mail.ini and restart Apache
/etc/init.d/apache2 restart
Now, the mail() function should work as designed!
- Matthew Clark's blog
- 224 reads
-

Post new comment