1

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

4

2 回答 2

3

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

于 2010-01-11T17:24:08.537 回答
1

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

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

还:

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

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

于 2010-01-11T17:37:45.653 回答