Reputation: 143
An error with the php error_log function when selecting message_type 1 and sending an email. Any value I place in the extra_headers parameter, stops any email being received and the error created.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: error-404@'.substr($_SERVER['SERVER_NAME'],4)."\r\n";
$log = var_export(debug_backtrace(), true);
error_log("<HTML><body><h1>404 ERROR: $today</h1><br /><p>$log</p></body></HTML>", 1, "[email protected]", $headers);
mod_fcgid: stderr: PHP Warning: error_log(): Multiple or malformed newlines found in additional_header in .....
Current PHP version: 5.6.24
Thanks.
Upvotes: 0
Views: 460
Reputation: 1
Do not end extra_header with newline. Below code is OK:
error_log("sometext", 1, "[email protected]",
"Subject: Foo\nFrom: [email protected]");
Upvotes: 0
Reputation: 143
This has worked for me. Not too sure how correct this solution is.
//create a boundary string. It must be unique so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: $from_name <$from_mail> \r\nReply-To: $from_mail";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: text/html; charset=\"iso-8859-1\"; boundary=\"PHP-alt-".$random_hash."\"";
error_log($sMsg, 1, $emailto, $headers);
I hope it helps somebody else.
Thank you for all your replies.
Upvotes: 0
Reputation: 72266
The documentation of function error_log()
for argument $extra_headers
says:
This message type uses the same internal function as
mail()
does.
The documentation of function mail()
says for $additional_headers
:
Multiple extra headers should be separated with a
CRLF
(\r\n
)
This is (I hope) the reason you use CRLF
(\r\n
) to separate the lines in the mail header.
However, the same documentation page also says in a note, several paragraphs below:
If messages are not received, try using a
LF
(\n
) only. Some Unix mail transfer agents (most notably» qmail
) replaceLF
byCRLF
automatically (which leads to doublingCR
ifCRLF
is used). This should be a last resort, as it does not comply with» RFC 2822
.
I cannot tell about qmail
but I encountered the same behaviour when the email server was sendmail
. The problem vanished when I used LF
(\n
) as the end-of-line marker in the headers.
Upvotes: 1