Saturday, 7 September 2013

Multipart/alternative with attachments

Multipart/alternative with attachments

I'm trying create a multipart/mixed email with multipart/alternative
(html/text) as one part and the attachment(s) as the other part.
I found an answer here , but couldn't get it to work.
What I did find out was to use multipart/alternative within
multipart/mixed, with different boundaries.
I found an example here. This example looks like what I was looking for,
but my code doesn't work. I get either an empty email with 3
attachents(.dat,.html & .pdf), or an an empty email with one binary '.dat'
attachment.
What's wrong with my code:
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--

No comments:

Post a Comment