使用PHP Mail格式化HTML

时间:2013-07-18 13:35:32

标签: php email

我在这里一直在研究这个主题: Sending HTML email from PHP

过去5个小时因某些原因无法让我的PHP生成HTML邮件。

这就是我所拥有的:

// Construct Mail:
$message = "<html><body>Some text<br />New line<p>New para</p></body></html>";
// Send Mail:
$to         = "$UserMail";
$subject        = "[Skills Exchange Network] Event Created";
$header     = 'MIME-Version: 1.0' . "\r\n";
$header     .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers    .= 'From: Skills Exchange Network <Mail Address is here>' . "\r\n";
$headers    .= 'Cc: Skills Exchange Network <Mail Address is here>' . "\r\n";
$SendMail   = mail($to,$subject,$message,$headers);

这是我收到的内容:

  

来自技能交流网络rnCc:技能交流网络

我真的不知所措......

这就是我现在所拥有的:

// Construct Mail:
$message = "<html><body>Some text<br />New line<p>New para</p></body></html>";

// Send Mail:
$to         = "$UserMail";
$subject        = "[Skills Exchange Network] Event Created";

// To send HTML mail, the Content-type header must be set
$headers     = "MIME-Version: 1.0" . "\r\n";
$headers    .= "Content-Type: text/html; charset=ISO-8859-1" . "\r\n";

// Additional Headers:
$headers    .= "From: Skills Exchange Network <info@skillsexchangenetwork.net>" . "\r\n";
$headers    .= "Cc: Skills Exchange Network <info@skillsexchangenetwork.net>" . "\r\n";
$SendMail   = mail($to, $subject, $message, $headers);

这就是我收到的内容:

Subject: [Skills Exchange Network] Event Created
MIME-Version: 1.0rnContent-Type: text/html; charset=ISO-8859-1rnFrom: Skills Exchange     Network <info@skillsexchangenetwork.net>rnCc: Skills Exchange Network <info@skillsexchangenetwork.net>rn
Message-Id: <E1UzptE-0003e1-Fs@wdt.webserversystems.com>
From: skillsex@wdt.webserversystems.com
Date: Thu, 18 Jul 2013 10:13:08 -0500
X-Antivirus: AVG for E-mail 2013.0.3349 [3204/6500]
X-AVG-ID: ID58DD9571-36429B43

<html><body>Some text<br />New line<p>New para</p></body></html>

3 个答案:

答案 0 :(得分:1)

您将$headers命名为$header,因此您的内容类型未嵌入。

$headers     = 'MIME-Version: 1.0' . "\r\n";
$headers    .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers    .= 'From: Skills Exchange Network <Mail Address is here>' . "\r\n";
$headers    .= 'Cc: Skills Exchange Network <Mail Address is here>' . "\r\n";

答案 1 :(得分:0)

也许你把's'放在$ header的末尾?

答案 2 :(得分:0)

PHPMailer可能是一个有用的解决方案。