简体   繁体   English

HTML无法在邮件功能中格式化

[英]HTML not formatting in mail function

I am using the following code: 我正在使用以下代码:

$message = "Hi ".$user.
  ",\r\rThe following names are on the guestlist for <b>".$night.
  "</b> on ".$date2.":\r\r". $user ."<br>". implode(", ", $names).
  "\r\rThank you for using Guestvibe.";

mail($email, "Your Guestvibe list", $message);

The carriage returns in PHP are working fine, but neither the <b> or <br> tags are coming out. PHP中的回车符工作正常,但是<b><br>标记都没有出现。 Is it just my mail client (Apple Mail) playing up, or is there a fix for this? 只是我的邮件客户端(Apple Mail)正在播放,还是有此修复程序?

You are sending the e-mail as text only not HTML, I believe you need to set these headers: 您仅以文本而不是HTML形式发送电子邮件,我相信您需要设置以下标头:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

as in example #4 of the docs . docs的示例4所示

PHP's mail function sends plaintext mail by default. PHP的mail功能默认情况下发送纯文本邮件。

See the nr.4 example at mail's manual page for the correct way to send HTML mail. 有关发送HTML邮件的正确方法,请参见邮件手册页上的nr.4示例。

You need to add your headers: 您需要添加标题:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($email, "Your Guestvibe list", $message, $headers);

You should firstly wrap the whole message into: 您应该首先将整个消息包装为:

<html><head></head><body> msg </body></html>

Plus headers from m.edmondson post. 加上m.edmondson帖子的标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM