问题
I'm sending a php html mail with this code:
$msg = "<p>Beste,</p> <p>Sorry, maar momenteel zijn deze CD uitverkocht. Daarom is uw order met ordernummer 15 opgesplits. Uw eerste order ( 15 ) wordt volgens planning geleverd.</p> <p>Het order nummer voor uw overige producten die niet geleverd kunnen worden is: 16. Deze hopen we zo spoedig mogelijk te leveren.</p> <p> </p> <p>Sorry voor het ongemak.</p> <p>Met Vriendelijke Groet,<br /> Wij</p> ";
$message = '<html dir="ltr" lang="en">' . PHP_EOL;
$message .= '<head>' . PHP_EOL;
$message .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . PHP_EOL;
$message .= '<title>Er zijn wijzigingen aangebracht aan uw order</title>' . PHP_EOL;
$message .= '</head>' . PHP_EOL;
$message .= '<body style="padding:0;margin:0;">' . $msg . '</body>' . PHP_EOL;
$message .= '</html>' . PHP_EOL;
$message = str_replace(array(chr(3)), '', $message);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ons <email@emailing.com>' . "\r\n";
mail($email, 'Er zijn wijzigingen aangebracht aan uw order', $message, $headers);
But the problem is that i'm getting the email as plain text (I can see the HTML tags). So what is the problem? As far as I know's are the headers properly set.
回答1:
Well, the answer is very simple.
After i looked at the source in gmail, i could see all these things: <p>
.
The problem was that the text was comming from an WYSIWYG editor, so all the entitys where encoded.
So after added this line, everything worked fine:
$message = html_entity_decode($message);
I hope that i could help somebody with this self answer.
来源:https://stackoverflow.com/questions/18738685/php-send-mail-with-html-not-working