Search code examples
phpemailgmailheader

Change mailed-by header in PHP mail


I've configured several headers in the mail() function, sender name and other fields appear as set. But, in the gmail mailed-by field, I see the hostname of my server, even though I've set the Mailed-By header to be different... Is there a way to change this, or am I specifying the wrong header to effect the change?

Current Headers:

From: [email protected]
Mailed-By: Example.com
X-Mailer: Example/1.0

Solution

  • If you post the headers you are sending it will be easier to diagnose the issue. But the header should be "X-Mailer" to set the application mailed-by field, as far as I know. If that does not work, post your current headers and we can help you further / better.

    EDIT:

    Doing some further research, it seems the 5th parameter with the "-f" flag would be the way to do it:

    mail($to, $message, $body, $headers, '[email protected]');

    Is a possibility. That is generally an email address, so you would have to see what values it accepts etc. I found this information from the Joyent Discussion Board.

    But reading that it may not be what you want.

    -fname Sets the name of the from'' person (i.e., the sender of the mail). -f can only be used by trusted'' users (normally root, daemon, and network) or if the person you are trying to become is the same as the person you are.

    From the sendmail Man page. I will see if I cannot strum anything else up.