tags:

views:

29

answers:

1

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 = '[email protected]';
$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 <[email protected]>';

mail($mailTo, $subject, $message, $headers);

I would expect the email to show up as being from Postmaster at the email address [email protected], but it is showing up as coming from [email protected], which is my hosting provider.

What did I not set up correctly?

A: 

Chris, try adding the \r\n after the <[email protected]>. 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.

jeerose
yup! that fixed it. Thanks!
zeckdude