Tim
Tim

Reputation: 145

PHP mail() headers, two to headers problem

This might be a dumb question but if I leave $to = '' in mail($to,...) and put $to to mail headers 'to' => '<[email protected]>', might this cause this effect(two 'to' headers)?:

To:
Subject: 123
From: <>
To: <[email protected]>

Upvotes: 2

Views: 254

Answers (2)

DaveRandom
DaveRandom

Reputation: 88657

Never really bothered to look at exactly how mail() behaves until now, just cracked out Wireshark and tried a couple of things and here is the result:


Test1

Message sends; To: header appears before From:

mail('[email protected]','Subject','Body',"From: [email protected]");

Test2

Message sends; To: header appears after From:

mail('[email protected]','Subject','Body',"From: [email protected]\r\nTo: [email protected]");

Test 3

Message wont send; PHP tries to do it but doesn't send an RCPT command, just skips straight to DATA which is a protocol violation so the server tells PHP to go away.

mail('','Subject','Body',"From: [email protected]\r\nTo: [email protected]");

Test 4

Message sends; both To: headers appear in the order they were specified in $additional_headers, after From:

mail('[email protected]','Subject','Body',"From: [email protected]\r\nTo: [email protected]\r\nTo: [email protected]");

Test 5

Message sends; To: header appears after From: and has the value specified in $additional_headers

mail('[email protected]','Subject','Body',"From: [email protected]\r\nTo: [email protected]");

So it appears that the To: header(s) specified in $additional_headers will override the one auto-generated by PHP from the value of $to, but you will never get multiple To: headers unless you explicitly set them in $additional_headers.

Tested on PHP 5.2.17/win32

Upvotes: 2

wanovak
wanovak

Reputation: 6127

You can have multiple to addresses, if that's what you mean:

mail('[email protected];[email protected]',...);

Upvotes: 0

Related Questions