PHP用HTML发送邮件不起作用 [英] PHP Send Mail with HTML not working

查看:71
本文介绍了PHP用HTML发送邮件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码发送php html邮件:

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);

但是问题是我收到的电子邮件是纯文本的(我可以看到HTML标记).那是什么问题呢?据我所知,标头设置正确.

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.

推荐答案

嗯,答案很简单.

在我查看了gmail的源代码之后,我可以看到所有这些东西:&lt;p&gt;.

After i looked at the source in gmail, i could see all these things: &lt;p&gt;.

问题是文本是从WYSIWYG编辑器输入的,因此所有实体都已编码.

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.

这篇关于PHP用HTML发送邮件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆