tags:

views:

165

answers:

2

Hi,

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?

A: 

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]') ) );
dkamins
COrrect Absolutely Correct
OM The Eternity
+1  A: 

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);
    ?>
OM The Eternity
This works indeed, but i still can't get it why my version doesn't include From header? I tried to add X-Mailer and Reply-To headers, too, but still no From-field in sent emails.
Nikkeloodeni
Try do the implode out of mail function and save it a variable and us that variable in mail function
OM The Eternity
Chk my direction for your code in my updated answer
OM The Eternity
did u used a separate variable in mail function for implode?
OM The Eternity
this is what i got:Content-Type: text/html; charset=UTF-8From: [email protected]
Nikkeloodeni
tried separate variable too. didn't help
Nikkeloodeni
Strange !! it should work in that case....
OM The Eternity