Change date header in PHP email?

Is it possible to manipulate the date header using the PHP / sendmail mail function (the website server is linux, so I believe it uses sendmail below)?

I am trying to check for error handling (Windows-based checks) and I need to create an invalid date header in the message, but when I send my message using php mail, even if I include the custom date header, it seems to be overridden by the mail server, and mine custom header is ignored. I assume that I might need an additional parameter for sendmail to fake this header, but I can’t find what this parameter will be, or it is even possible.

Here is what I send (with deleted personal domain information)

$headers = "From: ..................\r\n"; $headers .= "Message-ID: <" . md5(uniqid(time())) . "@..................>\n"; $headers .= "MIME-Version: 1.0\n"; //$headers .= "Date: ".date("D, d MYH:i:s") . " UT\n"; //a valid header for comparison $headers .= "Date: Tuesday\n"; // intentionally bogus email header $headers .= "Reply-To: ..................\n"; $headers .= "Return-Path: ..................\r\n"; $headers .= "X-Priority: 3\r\nX-MSMail-Priority: Normal\n"; $headers .= "X-Mailer: PHP/".phpversion()."\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1\n"; $headers .= "\n"; $success=mail($to, $s_subject, $s_emailmsg, $headers); 
+4
source share
1 answer

Assuming you wrote an email check that goes through procmail , the easiest way is to create your own email message and send it directly to the test script through standard input.

It is easier to write unit tests this way, since it bypasses any interference with other mail servers. When you do this, make sure the first line starts with MAIL FROM xx@yy.com .

+1
source

All Articles