The correct way to set the originator mailbox in the message headers (to something other than the actual Unix/Linux account that the script runs under the aegis of) is by supplying a From:
header to the mail()
function. There's no getting away from that. The correct way to set the originator mailbox in the message envelope is either using environment variables within some shim script, pointed to by sendmail_path
and wrapped around the actual sendmail
command, or using the UCB sendmail -f
option.
Andrew's given you a Postfix environment variable to set in the shim script. If you are using qmail you can in fact, per the qmail-inject
manual page, set both header and envelope originators, with the $QMAILUSER
+$QMAILHOST
+$QMAILNAME
(or $MAILUSER
+$MAILHOST
+$MAILNAME
or $USER
+$MAILHOST
+$NAME
) and $QMAILSUSER
+$QMAILSHOST
sets of environment variables respectively.