使用PHP';发送mime编码电子邮件的正确格式;s邮件

使用PHP';发送mime编码电子邮件的正确格式;s邮件,php,email,smtp,mime,Php,Email,Smtp,Mime,使用PHP的邮件功能创建mime多部分电子邮件以进行发送的正确方法是什么 $boundary = uniqid(rand(), true); $headers = "From: <noreply@example.com>\r\n"; $headers .= "Reply-To: <noreply@example.com>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .=

使用PHP的邮件功能创建mime多部分电子邮件以进行发送的正确方法是什么

    $boundary = uniqid(rand(), true);

    $headers =  "From: <noreply@example.com>\r\n";
    $headers .= "Reply-To: <noreply@example.com>\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: multipart/alternative; boundary=$boundary\r\n\r\n";
    $headers .= "This is a MIME encoded message.\r\n\r\n";
    $headers .= "--$boundary\r\n" .
                "Content-Type: text/plain; charset=ISO-8859-1\r\n" .
                "Content-Transfer-Encoding: base64\r\n\r\n";
    $headers .= chunk_split(base64_encode($plaintext));
    $headers .= "--$boundary\r\n" .
                "Content-Type: text/html; charset=ISO-8859-1\r\n" .
                "Content-Transfer-Encoding: base64\r\n\r\n";
    $headers .= chunk_split(base64_encode($body)); // chunk_split adds the ending "\r\n"
    $headers .= "--$boundary--\r\n";
    //$headers .= ".\r\n";

    mail($to, $subject, '', $headers);
$boundary=uniqid(rand(),true);
$headers=“From:\r\n”;
$headers.=“回复:\r\n”;
$headers.=“MIME版本:1.0\r\n”;
$headers.=“内容类型:多部分/可选;边界=$boundary\r\n\r\n”;
$headers.=“这是一条MIME编码的消息。\r\n\r\n”;
$headers.=“--$boundary\r\n”。
“内容类型:文本/普通;字符集=ISO-8859-1\r\n”。
“内容传输编码:base64\r\n\r\n”;
$headers.=chunk_split(base64_encode($plaintext));
$headers.=“--$boundary\r\n”。
“内容类型:text/html;charset=ISO-8859-1\r\n”。
“内容传输编码:base64\r\n\r\n”;
$headers.=chunk_split(base64_encode($body));//chunk\u split添加结尾“\r\n”
$headers.=“--$boundary--\r\n”;
//$headers.=“\r\n”;
邮件($to、$subject、,$headers);
我尝试了上述方法,但PHP似乎忽略了它,而是发送我在服务器上收到的这封空电子邮件:

...
...
To: <....>
Subject: Test Email
X-PHP-Originating-Script: 0:Mail.php
From: <noreply@example.com>
Reply-To: <noreply@example.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="1923630041519679ed1ddd25.14582240"
Message-ID: <20130517184149.28AB0A4C4@example.com>
Date: Fri, 17 May 2013 14:41:49 -0400
X-UI-Loop: V01:211ZxL2TMQ4=:uQC6SYy+5ULsBgI8/Yn6FAKnX8a66b5mzBQJFWhGo82c
 3a8ZtvbDIKAYJ3vIkfg3

--1923630041519679ed1ddd25.14582240
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: base64


--1923630041519679ed1ddd25.14582240
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: base64


--1923630041519679ed1ddd25.14582240--
。。。
...
致:
主题:测试电子邮件
X-PHP-origing-Script:0:Mail.PHP
发件人:
答复:
MIME版本:1.0
内容类型:多部分/备选;
边界=“1923630041519679ED1DD25.14582240”
消息ID:
日期:2013年5月17日星期五14:41:49-0400
X-UI-Loop:V01:211ZxL2TMQ4=:uQC6SYy+5ULsBgI8/Yn6FAKnX8a66b5mzBQJFWhGo82c
3a8ZtvbDIKAYJ3vIkfg3
--1923630041519679ED1DD25.14582240
内容类型:文本/纯文本;charset=“ISO-8859-1”
内容传输编码:base64
--1923630041519679ED1DD25.14582240
内容类型:text/html;charset=“ISO-8859-1”
内容传输编码:base64
--1923630041519679ED1DD25.14582240--

在PHP5.4.9上进行了测试。

我使上述代码正常工作。似乎我需要用linux
\n
替换所有的windows
\r\n
。我还删除了
边界=“…”
之后的重复换行符