Why is the From line not working on my mail function?
I am using a mail function to send html to an email address, but the From name and email address aren't showing up. This is my code:
$name = $_POST['name'];
$mailTo = 'name@email.com';
$subject = 'Message from ' . $_POST['name'];
$message =
'<html>
<head>
<title>HTML email</title>
</head>
<body>
<p><b>Name:</b> ' . $_POST['name'] . '</p>
<p><b>Email:</b> ' . $_POST['email'] . '</p>
<p><b>Message:</b> ' . $_POST['mainmessage'] . '</p>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Postmaster <some@b开发者_Go百科ody.com>';
mail($mailTo, $subject, $message, $headers);
I would expect the email to show up as being from Postmaster at the email address some@body.com, but it is showing up as coming from ideapale@box486.bluehost.com, which is my hosting provider.
What did I not set up correctly?
Chris, try adding the \r\n
after the <some@body.com>
. I've found that php can be very picky when talking to mail servers.
Edit: just to help a little more, I have this (almost exactly what you have) in one of my working scripts:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$to . "\r\n";
$headers .= 'From: ' .$from. "\r\n";
...where $from = $fromname.' <'.$fromemail.'>';
and $to is just an email address.
精彩评论