使用PHP发送多部分/备用电子邮件时出现问题

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了使用PHP发送多部分/备用电子邮件时出现问题脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这是构建/发送邮件的脚本:
$boundary = md5(date('U'));

$to = $email;
$subject = "My Subject";

$headers = "From: myaddress@mydomain.COM" . "\r\n".
           "X-Mailer: PHP/".PHPversion() ."\r\n".
           "MIME-Version: 1.0" . "\r\n".
           "Content-tyPE: multipart/alternative; boundary=--$boundary". "\r\n".
           "Content-transfer-encoding: 7bIT". "\r\n";

$text = "You really ought remember the birthdays";     
$htML = '<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>
    ';

$message = "Multipart Message coming up" . "\r\n\r\n".
       "--".$boundary.
       "Content-Type: text/plain; charset=\"iso-8859-1\"" .
       "Content-transfer-encoding: 7bit".
       $text. 
       "--".$boundary. 
       "Content-Type: text/html; charset=\"iso-8859-1\"". 
       "Content-transfer-encoding: 7bit". 
       $html.
       "--".$boundary."--";



mail("toAddress@example.com",$subject,$message,$headers);

它发送消息就好了,我的收件人收到了它,但是他们用text / plain而不是multipart / alternative来获取整个内容.查看收到的消息的来给出了这一点(删除了许多内容):

Delivered-To: myrecipient@example.com
Received: by 10.90.100.4 with SMTP id x4cs111413agb;
    Wed,25 Mar 2009 16:39:32 -0700 (PDT)
Received: by 10.100.153.6 with SMTP id a6mr85081ane.123.1238024372342;
    Wed,25 Mar 2009 16:39:32 -0700 (PDT)
Return-Path: <xxx@xxxx.com>
--- snip ---
Date: Wed,25 Mar 2009 17:37:36 -0600 (MDT)
Message-id: <200903252337.n2PNbaw2019541@www.xxxxxxx.com>
To: trevor@saturdayplace.com
Subject: My Subject
From: me@mydomain.com
X-Mailer: PHP/4.3.9
MIME-Version: 1.0
Content-Type: text/plain;
boundary="--66131caf569f63b24f43d529d8973560"
Content-transfer-encoding: 7bit
X-OriginalArrivalTime: 25 Mar 2009 23:38:30.0531 (UTC) FILETIME=[CDC4E530:01C9ADA2]
X-TM-AS-PRoduct-Ver: SMEX-8.0.0.1181-5.600.1016-16540.005
X-TM-AS-Result: No--4.921300-8.000000-31
X-TM-AS-User-Approved-sender: No
X-TM-AS-User-Blocked-Sender: No


Multipart Message coming up

--66131caf569f63b24f43d529d8973560
Content-Type: text/plain; charset="iso-8859-1"
Content-transfer-encoding: 7bit

You really ought remember the birthdays

--66131caf569f63b24f43d529d8973560
Content-Type: text/html; charset="iso-8859-1"
Content-transfer-encoding: 7bit

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


--66131caf569f63b24f43d529d8973560--

看起来内容类型标题在从multipart / alternative到text / plain的过程中发生了变化.我不是系统管理员,所以如果这是一个sendmail问题,我就在我脑海中.有什么建议?

这条线
"Content-Type: multipart/alternative; boundary=--$boundary". "\r\n".

应该

"Content-Type: multipart/alternative; boundary=$boundary". "\r\n".

您不在标题中包含短划线.

脚本宝典总结

以上是脚本宝典为你收集整理的使用PHP发送多部分/备用电子邮件时出现问题全部内容,希望文章能够帮你解决使用PHP发送多部分/备用电子邮件时出现问题所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。