Reputation: 93
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( '[email protected]', 'Example subject', $msg,
implode( '\r\n', array( 'Content-Type: text/html; charset=UTF-8', 'From: [email protected]') ) );
As i said everything works fine except From field is all blank when the message arrives. Any ideas why this is happening?
Upvotes: 3
Views: 3278
Reputation: 16234
Try this
<?php
$to = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\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: [email protected]') );
echo "<pre>";
print_r($implode);
?>
Upvotes: 2
Reputation: 21918
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( '[email protected]', "Example subject", $msg,
implode( "\r\n", array( 'Content-Type: text/html; charset=UTF-8', 'From: [email protected]') ) );
Upvotes: 1