Search code examples
phpemailsendmailemail-headersmail-sender

Set Sender-header with mail()


Short version of question:

How can I set the Sender: header to [email protected] when mailing with mail() in PHP?

(That is the Sender: header, NOT the From: header)

Long version:

We have issues with our server sent mail being falsely identified as SPAM. Ordinary mail (from mail clients) does not have that problem (DKIM/SPF all OK).

The big difference between the normal and server sent mail is the "Sender:" header. When sending mail from a mail client all is well:

From: [email protected]
X-Sender: [email protected]

The headers on a mail sent via PHP read:

From: [email protected]
Sender: [email protected]  

That 2nd mailaddress does exist but I absolutely don't want our admin mail address there. And the admin address makes some mail servers think it is SPAM -- which it is absolutely NOT. (It is seen as SPAM, since, even though we have an MX record and SPF record in the DNS for vps1949.ourvpsprovider.com, these are somehow not recognised by the mailservers. I am only medium experienced with DNS, not enough to understand why this happens.)

ourdomain.com and vps1949.ourvpsprovider.com of course point to the same IP.

So how can I set the Sender: header to [email protected] when mailing with mail() in PHP? That would solve it for us.

(That is the Sender: header, NOT the From: header)

This would solve all our problems.

No luck on Google, I've searched for hours and tried several things to no avail. (The -f flag on sendmail is NOT a solution, for instance.)

Since we have a VPS, I have full server access, so altering or adding an ini file is possible, if needed. (I could not find a sendmail.ini.)

Anyone can help?


Solution

  • I solved it by changing the host name on the server. I found How to change envelope from address using PHP mail? and took the answer that everybody disliked. It worked. Finally, took weeks and weeks to find this... So easy.

    For anyone who has the same and happens to be running on CentOs 7: http://www.itzgeek.com/how-tos/linux/centos-how-tos/change-hostname-in-centos-7-rhel-7.html