1

Whenever i send an email in php with the mail() function, when i receive it as a user, the e-mail is shown as sent from "[email protected]".

Now i want that to be sent from "[email protected]" as a standard, without having to set the "From:" header in the mail() function when i send it.

I am not sure how to change this, so a little help would be nice.

I run CentOS 5.6 with a somewhat normal LAMP setup.

3 Answers 3

1

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.

1

The best options in the circumstance you request are probably either

  • Use sendmail_from in php.ini
  • or change the hostname of the host (either in /etc/hostname or the host name directive in your postfix/sendmail configuration)
3
  • The sendmail_from in the php.ini is only for windows, i run linux, but i'll take a look at option nr. 2... Jun 20, 2011 at 22:05
  • Changing the hostname makes half the problem go away, the senders name is still anonymous, but other than that thanks. +1 Jun 21, 2011 at 4:03
  • Is 'anonymous' a valid user on your system? Typically in a LAMP setup the emails sent are from www-data@hostname or similar - the apache/php process owner.
    – thinice
    Jun 21, 2011 at 18:44
1

The postfix sendmail man page suggests using the NAME environment variable.

(Aside: the die.net man page didn't mention it...)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .