PHP Send Mail with HTML not working

回眸只為那壹抹淺笑 提交于 2019-12-11 04:33:55

问题


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>&nbsp;</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: &lt;p&gt;.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!