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
user@hostname (given you are logged in as
user and the machine is called
But I found a better way (maybe even easier to extend). Just change the
sendmail_path to something with an extra
-f email@example.com at the end.
The config in php.ini looks like this:
sendmail_path = /usr/sbin/sendmail -t -i -f firstname.lastname@example.org
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@example.com
Dont forget to restart php-fpm after this change!
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" firstname.lastname@example.org -- -f email@example.com # sends mail to firstname.lastname@example.org from email@example.com