2

I am using the php mail function to send emails. I pass in the to address and I also build out some additional email headers, including From: and Reply-To:.

However until now I have also been including a To: header in the additional headers. For eg i would pass email "user@email.com" to the mail function but in addition I will be including a to header below as part of the header.

 "To:Users Name <user@email.com>"

The result is that php mail includes a To: header TWICE in the email, once with the email address (as passed into the first param of the function) and the other as part of the header param passed to php mail.

TO: user@email.com
TO: Users Name <user@email.com>

As a result it is getting blocked by some spam systems.

So have a few questions:

  • is there any real benefit including a full To: header which has the recipients name and email as opposed to just having a TO: header of "user@gmail.com" without the recipients name.

  • Is there any reason not to just pass the full to header (ie name & email) into the first param of the mail function and just leave it out of the additional header param.

Looking for the right approach here. Thanks

Gotts
  • 2,274
  • 3
  • 23
  • 32

1 Answers1

1

Is there any real benefit including a full To: header which has the recipients name and email as opposed to just having a TO: header of "user@gmail.com" without the recipients name?

Yes: From the RFC 2822 - Internet Message Format - 3.4. Address Specification

Normally, a mailbox is comprised of two parts: (1) an optional display name that indicates the name of the recipient (which could be a person or a system) that could be displayed to the user of a mail application, and (2) an addr-spec address enclosed in angle brackets ("<" and ">"). There is also an alternate simple form of a mailbox where the addr-spec address appears alone, without the
recipient's name or the angle brackets.

There are email clients that will use the format to actually display the name together/in stead of the email address which makes it more readable to the users. And as you can see, only using the single address is seen as an alternative to the fully two parts.

Is there any reason not to just pass the full to header (ie name & email) into the first param of the mail function and just leave it out of the additional header param?

No, you can just use the first parameter, The mail() to-parameter complies with RFC 2822.

Community
  • 1
  • 1
Timmetje
  • 7,641
  • 18
  • 36