【问题标题】:PHP HTML mail rendering tags in outlookOutlook中的PHP HTML邮件渲染标签
【发布时间】:2011-01-03 20:23:27
【问题描述】:

我在 PHP 站点上使用此示例发送 HTML 电子邮件,但是当我收到脚本发送的邮件时,它会在客户端 (Outlook) 中呈现标签

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title> 
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
  <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
  <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
  <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
 </table>
</body>
 </html>
 ';

// 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 .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

我的客户端设置为接收 HTML 邮件 - 所以我不确定发生了什么。有什么指点吗?

【问题讨论】:

    标签: php html-email


    【解决方案1】:

    我不知道如何修复您现有的脚本,但是对于发送 HTML 电子邮件,我总是建议使用像 PHPMailer 这样的现成类:它提供了对多部分邮件、多个收件人的安全和干净的处理,甚至文件附件。

    【讨论】:

    • 我支持这个答案。邮件是如此复杂,以至于使用现有的类总是一个好主意。我个人最近使用过 Zend_Mail,但您可以自行选择最喜欢的内容。
    【解决方案2】:

    您的代码对我有用。如果 Outlook 有查看邮件原始源代码的功能,您应该仔细检查它,看看是否有问题。

    如果您碰巧混合了 Windows 和 Unix 样式的换行符,电子邮件客户端有时会忽略某些标题。

    还有:

    • 不要显式添加 To 标头。 PHP 会为你做这件事。

    • 删除 $headers 中的前导回车。

    【讨论】:

      猜你喜欢
      • 2016-12-17
      • 2015-01-22
      • 2011-09-17
      • 2016-10-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 2018-12-09
      相关资源
      最近更新 更多