I want to send an email using Zend which will have few inline images and a pdf file as attachment, the code of the email should look something like this:
From - Wed Apr 18 12:09:29 2012
[...]
Content-Type: multipart/mixed; boundary=mixed6455A4FA01BD9CFD334A87E206713ED8
[...]
--mixed6455A4FA01BD9CFD334A87E206713ED8
Content-Type: multipart/related; boundary=related6455A4FA01BD9CFD334A87E206713ED8
--related6455A4FA01BD9CFD334A87E206713ED8
Content-Type: multipart/alternative; boundary=alternative6455A4FA01BD9CFD334A87E206713ED8
--alternative6455A4FA01BD9CFD334A87E206713ED8
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Email as plain text
best regards
--alternative6455A4FA01BD9CFD334A87E206713ED8
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Email as <b>html</b><br />
<img src = 'cid:dvb_small.jpg' border = '0'/><br /><br/ >
best regards
<img src = 'cid:signature.gif' border = '0'/>
--alternative6455A4FA01BD9CFD334A87E206713ED8--
--related6455A4FA01BD9CFD334A87E206713ED8
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <dvb_small.jpg>
Content-Disposition: inline
[IMAGE CONTENT]
--related6455A4FA01BD9CFD334A87E206713ED8
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-ID: <signature.gif>
Content-Disposition: inline
[IMAGE CONTENT]
--related6455A4FA01BD9CFD334A87E206713ED8--
--mixed6455A4FA01BD9CFD334A87E206713ED8
Content-Type: application/octetstream; name="invoice_7293.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="invoice_7293.pdf"
[PDF CONTENT]
--mixed6455A4FA01BD9CFD334A87E206713ED8--
Is there a way to get such code using Zend_Mail? What am I doing now is:
$mail = new Zend_Mail;
[...]
//Adding inline images
$att = $mail->createAttachment(file_get_contents($filePath));
$att->type = $fileType['mime'];
$att->disposition = Zend_Mime::DISPOSITION_INLINE;
$att->encoding = Zend_Mime::ENCODING_BASE64;
$att->filename = $fileName;
$att->id = md5($att->filename);
//Adding PDF file
$invoiceAt = $mail->createAttachment(file_get_contents($invoicePdf));
$invoiceAt->type = 'application/octetstream';
$invoiceAt->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$invoiceAt->encoding = Zend_Mime::ENCODING_BASE64;
$invoiceAt->filename = 'invoice_' . $id . '.pdf';
The last thing to do is to set the proper email content type. If I use:
$this->setType(Zend_Mime::MULTIPART_MIXED);
The inline files are not displayed, they are attached to the email.
If I do this:
$this->setType(Zend_Mime::MULTIPART_RELATED);
The inline files are displayed properly, but the pdf attachment isn't (it is there and one can open it, but f.e. in Thunderbird you see the attachement sign only after clicking on the mail). I assume other mail clients will also have problems with it.
The generated email code looks in that case like this:
From - Wed May 02 15:12:18 2012
[...]
Content-Type: multipart/related;
boundary="=_c3a05d0d4a6abdbfcb3fc03ac8abf402"
Content-Transfer-Encoding: quoted-printable
[...]
--=_c3a05d0d4a6abdbfcb3fc03ac8abf402
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
[HTML]
--=_c3a05d0d4a6abdbfcb3fc03ac8abf402
Content-Type: application/octetstream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="invoice_123.pdf"
[PDF_CONTENT]
--=_c3a05d0d4a6abdbfcb3fc03ac8abf402
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <e783669dda40eced6adef6cd056d9887>
Content-Disposition: inline; filename="dvb_logo.jpg"
[IMAGE CONTENT]
--=_c3a05d0d4a6abdbfcb3fc03ac8abf402
Content-Type:
Content-Transfer-Encoding: base64
Content-ID: <0c6120573af00f1160ee7049be5835c3>
Content-Disposition: inline; filename="signature.gif"
[IMAGE CONTENT]
--=_c3a05d0d4a6abdbfcb3fc03ac8abf402--
So, is there any way in Zend to generate the email code like on the top of my question?