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 "anonymous@MyServerName.local".

Now i want that to be sent from "mail-bot@mydomain.com" 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 Answers3

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)
thinice
  • 4,716
  • 21
  • 38
  • The sendmail_from in the php.ini is only for windows, i run linux, but i'll take a look at option nr. 2... – Kristoffer la Cour Jun 20 '11 at 22:05
  • Changing the hostname makes half the problem go away, the senders name is still anonymous, but other than that thanks. +1 – Kristoffer la Cour Jun 21 '11 at 04: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 '11 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...)

Andrew
  • 8,002
  • 3
  • 36
  • 44
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.

JdeBP
  • 3,990
  • 18
  • 17