我在 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 邮件 - 所以我不确定发生了什么。有什么指点吗?

有帮助吗?

解决方案

我不知道如何解决现有的脚本,但发送HTML电子邮件,我总是建议用现成的类象的 <强> PHPMailer的 :提供多部分邮件,多个接收者的安全和清洁处理,甚至文件附件。

其他提示

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

有时,如果您碰巧混合使用 Windows 和 Unix 风格的换行,电子邮件客户端会忽略某些标头。

还:

  • 不要添加 明确标头。PHP 会为你做这件事。

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top