dracoblue.net

Set Sender/Reply-To for sendmail in PHP

Today I tried to configure the sender for sendmail in php. There are some ways how to do it, so I share my solution.

There is a sendmail_from setting in php cli and php fpm, but it is usually empty. So sendmail fallsback to [email protected] (given you are logged in as user and the machine is called hostname).

But I found a better way (maybe even easier to extend). Just change the sendmail_path to something with an extra -f [email protected] at the end.

The config in php.ini looks like this:

sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]

If you want to change it in PHP-FPM, you can do this for each pool (e.g. /etc/php5/pool.d/www.conf) by appending:

php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f [email protected]

Dont forget to restart php-fpm after this change!

That's it.

As a small bonus: If you want to send a mail from commandline/bash with a proper sender address, it works like this:

$ echo "The mail body" | mail -s "The Subject" [email protected] -- -f [email protected]
# sends mail to [email protected] from [email protected]

In open source, php, sendmail, ubuntu by @ 09 Jul 2014

comments powered by Disqus

Recent Files

Advertisement

Recent Dev-Articles

Read recently

About

Blogroll