php 邮件功能与 html 在交换中未正确显示

发布于 2024-09-26 10:29:14 字数 3780 浏览 1 评论 0原文

我在 php 邮件和交换方面遇到了一个奇怪的问题。当我使用简单的 php html 邮件脚本时,请参见下文(可以在整个互联网上找到),我在 Microsoft Exchange 中将邮件视为纯文本(请参见下文)邮件。但是,当我使用 Outlook 将邮件发送到其他帐户时,我看到的邮件应该是 HTML 邮件。

有人有线索吗?

邮件脚本:

<?php
// multiple recipients
$to  = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';

// 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 <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

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

在 Exchange 中查看:

Content-type: text/html; charset=iso-8859-1

From: Birthday Reminder <[email protected]>
Subject:Birthday Reminders for August

Return-Path: [email protected]
X-OriginalArrivalTime: 06 Oct 2010 13:39:59.0117 (UTC) FILETIME=[F839FBD0:01CB655B]

<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>

I got a strange problem with php mail and exchange. When I use the a simple php html mailscript, see below (can be found all over internet) I see the mail as kind of plain text (see below) mail in Microsoft Exchange. But when I send the mail to an other account with Outlook I see the mail as a HTML-mail as it should be.

Doest anybody got a clue?

Mailscript:

<?php
// multiple recipients
$to  = '[email protected]' . ', '; // note the comma
$to .= '[email protected]';

// 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 <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

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

View in Exchange:

Content-type: text/html; charset=iso-8859-1

From: Birthday Reminder <[email protected]>
Subject:Birthday Reminders for August

Return-Path: [email protected]
X-OriginalArrivalTime: 06 Oct 2010 13:39:59.0117 (UTC) FILETIME=[F839FBD0:01CB655B]

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一口甜 2024-10-03 10:29:14

尝试将标题中的 "\r\n" 替换为 "\n"

try replace the "\r\n" to "\n" in the headers

难忘№最初的完美 2024-10-03 10:29:14

您是否尝试过使用 Content-Type 而不是 Content-type? (类型大写)

Have you tried using Content-Type instead of Content-type? (capitalize the type)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文