Nullmailer Sender Address

Nullmailer is small mail relay agent to forward mails to a full featured mailserver. In some cases you will recognize, that the envelope sender address is not the one you wish to have. Usally - e.g. on a commandline - you will use the  -f  switch to set the envelope sender address. But in some cases this is not possible, e.g. if you use the mail function of PHP running under the user of the service.

As a roadmap of a workaround, create a file  /usr/local/bin/sendmail  with content like:

#!/bin/bash
 
export NULLMAILER_USER=<sendername>
export NULLMAILER_FLAGS=s
 
/usr/sbin/sendmail $@

and make it executable. This sets the envelope sender address fix to  <sendername>@<hostname>  . Replace  <sendername>  to whatever you want to use (without the brackets). To be more flexible set the environment variable  NULLMAILER_USER  outside of the script and before you invoke it.

To stay with PHP, you have to tell PHP to use the new script. As one of the option you cannot change/overwrite anywhere - like in a .htaccess - you have to edit the  php.ini  file

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "/usr/local/bin/sendmail"

As otherwise stated, supplying an argument  sendmail -f  here didn't work for me.

Be aware of the $PATH variable - keep in mind, that it can be different depending on the situation!

This means that the  /usr/local/bin/sendmail  can/will be executed before the original one in  /usr/bin/  . It is a good idea to use the full path to a file whenever it's possible always, not at least in shell scripts.