我正在尝试创建multipart/mixed
一封电子邮件,其中multipart/alternative
(html/text)作为一部分,附件作为另一部分。
我在这里找到了答案 ,但无法正常工作。
我发现是在不同的边界multipart/alternative
内使用。multipart/mixed
我在这里找到了一个例子。这个例子看起来像我要找的,但我的代码不起作用。我收到一封带有 3 个附件(.dat、.html 和 .pdf)的空电子邮件,或者一封带有一个二进制“.dat”附件的空电子邮件。
我的代码有什么问题:
Date: Sun, 08 Sep 2013 10:38:15 +0700
Subject: Login details for Test
To: test@test.com
X-PHP-Originating-Script: 0:Mail.class.php
from: no_reply@localhost
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="38651c4450f87348fcbe1f992746a954"
--38651c4450f87348fcbe1f992746a954
Content-Type: mixed/alternative; boundary="sub_38651c4450f87348fcbe1f992746a954"
--sub_38651c4450f87348fcbe1f992746a954
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
Plain text message
--sub_38651c4450f87348fcbe1f992746a954
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
Dear [realname],<br><br>
You've requested to resend your login credentials for Test.<br><br>
<b>HTML</b> message
--sub_38651c4450f87348fcbe1f992746a954--
--38651c4450f87348fcbe1f992746a954
Content-Type: application/octet-stream; name="test.pdf"
Content-Disposition: attachment;
filename="test.pdf"
Content-Transfer-Encoding: base64
JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAy
IDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0ZsYXRlRGVj
etc, etc
--38651c4450f87348fcbe1f992746a954--