Strange things happening to me. I’m trying to send a HTML mail, using the php mail() function, but no luck here. Even when I copy/paste a piece of code literally, it doesn’t work. What am I doing wrong? Here is the piece of code I use:
$message = "<html><body>";
$message .= "<table rules='all' style='border-color: #666;' cellpadding='10'>";
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$to = 'me@gmail.com';
$subject = 'Website Change Reqest';
$headers = "From: " . $email . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (mail($to, $subject, $message, $headers)) {
echo 'Your message has been sent.';
} else {
echo 'There was a problem sending the email.';
}
And this is what my e-mail looks like…:
Reply-To: me@gmail.com
MIME-Version: 1.0
Content-Type: text/html; charset=ISO-8859-1
Message-Id: <20110703234551.A9D6153DAB@apache10.hostbasket.com>
Date: Mon, 4 Jul 2011 01:45:51 +0200 (CEST)
<html><body><table rules="all" style="border-color: #666;" cellpadding="10"><tr style='background: #eee;'><td><strong>Name:</strong> </td></tr><tr><td><strong>Email:</strong> </td></tr><tr><td><strong>Type of Change:</strong> </td></tr><tr><td><strong>Urgency:</strong> </td></tr><tr><td><strong>URL To Change (main):</strong> </td></tr><tr><td><strong>NEW Content:</strong> </td></tr></table></body></html>
What do I do wrong?
We can’t see where the variable
$emailwas set, but I’m guessing that there might be an extra line break at the end of your$emailvariable. This would have the effect of putting in two linebreaks after theFrom:header and before theReply-to:, which signals the start of the body of the message and the completion of the headers.Try:
before constructing the message. Since there appears to be an extra line break after the
Reply-toheader as well, my case is even stronger for an extra break in$email.UPDATE
Also try changing the linebreaks to PHP’s native format on the system where the code will run. This is done by replacing
\r\nwithPHP_EOL