我想使用Zend发送一封电子邮件,其中几乎没有内嵌图片和pdf文件作为附件,电子邮件的代码应如下所示:
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--
有没有办法使用Zend_Mail获取此类代码?我现在在做什么:
$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';
最后要做的是设置正确的电子邮件内容类型。如果我使用:
$this->setType(Zend_Mime::MULTIPART_MIXED);
不会显示内嵌文件,它们会附加到电子邮件中。
如果我这样做:
$this->setType(Zend_Mime::MULTIPART_RELATED);
内联文件显示正确,但pdf附件不是(它可以打开它,但是在Thunderbird中,只有在点击邮件后才会看到附件标志)。我认为其他邮件客户端也会遇到问题。
生成的电子邮件代码就像这样:
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--
那么,Zend有什么方法可以像我的问题一样生成电子邮件代码吗?