Php邮件功能不以html格式发送 [英] Php mail function not sending in html format

查看:124
本文介绍了Php邮件功能不以html格式发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,我试图以HTML格式发送电子邮件。到目前为止,我有这个

  $ subject =密码提醒; 
$ message =您的密码为< b> {$ password}< / b>。< br />< br />< br />< br /> ;
$ message = wordwrap($ message,70,\\\\);
$ headers ='From:me@gmail.com'。 '\\\\'。
'回覆:me@gmail.com'。 '\\\\'。
'X-Mailer:PHP /'。 phpversion()。 '\\\\'。
'MIME版本:1.0\r\\\
'。 '\\\\'。
'Content-Type:text / html;字符集= ISO-8859-1\r\\\
;

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

我遵循本指南: http://css-tricks.com/sending-nice-html-email-with-php/



但是当我收到电子邮件时,它会显示标签,我希望它将标签解释为html。



有没有人知道有什么问题?



谢谢。

解决方案

问题:'MIME-Version:1.0\r\\\
'。 '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'因此,您的内容类型声明text / html正在被解析为邮件正文,而它属于标题。



删除一个终端,它应该工作:



'MIME版本:1.0\r\\\
'我也注意到您使用单引号 \r\\\
。你应该使用双引号,否则它们将被转义。你需要他们解析。

 'From:me@gmail.com'。 \\\\。 
'回覆:me@gmail.com'。 \\\\。
'X-Mailer:PHP /'。 phpversion()。 \\\\。
'Content-Type:text / html;字符集= ISO-8859-1’ 。 \r\\\

'MIME-Version:1.0'。\r\\\
\r\\\
;


In PHP, I'm trying to send emails in HTML format. So far I have this

            $subject = "Password Reminder";
            $message = "Your password is <b>{$password}</b>.<br/><br/><br/><br/>me";
            $message = wordwrap($message, 70, "\r\n");
            $headers = 'From: me@gmail.com' . '\r\n' .
                'Reply-To: me@gmail.com' . '\r\n' .
                'X-Mailer: PHP/' . phpversion() . '\r\n' .
                'MIME-Version: 1.0\r\n' . '\r\n' .
                'Content-Type: text/html; charset=ISO-8859-1\r\n';

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

I followed this guide: http://css-tricks.com/sending-nice-html-email-with-php/

But when I get the email, it shows with the tags, I want it to interpret the tags into html.

Does anyone know whats wrong?

Thanks.

解决方案

this is most likely the problem: 'MIME-Version: 1.0\r\n' . '\r\n' .

after two endlines the headers end and the body starts. So your content-type declaration of text/html is being parsed as message body, while it belongs to headers.

remove one endline and it should work:

'MIME-Version: 1.0\r\n'

also I noticed you use single quotes for \r\n. You should use double quotes or else they will be escaped. You need them to be parsed.

 'From: me@gmail.com' . "\r\n" .
                'Reply-To: me@gmail.com' . "\r\n" .
                'X-Mailer: PHP/' . phpversion() . "\r\n" .
                'Content-Type: text/html; charset=ISO-8859-1'."\r\n".
                'MIME-Version: 1.0'."\r\n\r\n";

这篇关于Php邮件功能不以html格式发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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