mail sent with php's mail() has blank From field
I'm sending email with PHP's mail function. It works just as it should except all email clients show blank From-field. Here's how i'm using the function:
mail( 'mail@example.com', 'Example subject', $msg,
implode( '\r\n', array( 'Content-Type: text/html; charset=UTF-8', 'From: test@example.com') ) );
As i said everything works fine except From fiel开发者_StackOverflow中文版d is all blank when the message arrives. Any ideas why this is happening?
Try this
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Against Your idea Check this what you get
<?php
$implode =implode( "\r\n", array( 'Content-Type: text/html; charset=UTF-8', 'From: test@example.com') );
echo "<pre>";
print_r($implode);
?>
You're missing a quote before your "Content-Type" and probably have error logging turned way down so it's ignoring the problem and getting all confused with parsing your code.
Should be:
mail( 'mail@example.com', "Example subject", $msg,
implode( "\r\n", array( 'Content-Type: text/html; charset=UTF-8', 'From: test@example.com') ) );
精彩评论