php mail() headers problem
here is my code....
$subject = "This is Subject";
$headers .= 'Content-type: text/html; charset=iso-8859-1';
$to = 'foo@foo.com';
$body = 'Mail Content Here';
mail($to, $subject, $body, $headers);
but when i open this file开发者_Python百科 it sends a mail to $to
successfully but with wrong headers....and my hosting server default address i.e mars.myhosting.com, instead of mydomain@domain.com how can i fix that
Look at this from php.net
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: Webmaster <webmaster@example.com>' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Add the from header
Here is what I would do via PHP:
<?PHP
$to = 'email@address.com';
$subject = 'desired subject';
$message = 'desired message';
$headers = 'From: example@email.com' . "\r\n" .
'Reply-To: example@email.com' . "\r\n" .
'Return-Path: example@email.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
I hope that helps some :)
精彩评论