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
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!
As a small bonus: If you want to send a mail from commandline/bash with a proper sender address, it works like this: