I am trying to send an email using the Zend_Mail class that will include text in HTML format, a plain text alternative and inline images referenced in the HTML. I only want the images to show embedded, but not as attachments.
My current code is the following:
$mail = new Zend_Mail('UTF-8');
$mail->addTo($recipient);
$mail->setFrom($sender);
$mail->setSubject($subject);
$mail->setBodyText($text);
$mail->setBodyHtml($html);
$images = array('name1','name2','name3');
foreach ($images as $i){
$filename = Zend_Registry::get('config')->path->localimages . '/' . $i . '.png';
$at = new Zend_Mime_Part(file_get_contents($filename));
$at->filename = $i . '.png';
$at->type = 'image/png';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_BASE64;
$at->id = $i;
$mail->addPart($at);
}
$mail->send();
Since both setBodyText() and setBodyHtml() are used, Zend automatically generates a multipart/alternative MIME message. The images are then shown embedded on the HTML code but also as attachments.
I want the images to only show embedded. For that, I understand I would need to have the text and html inside a MIME part with type multipart/alternative, and then to set the type of the whole email to multipart/related. How can I achieve this in Zend 1.10? I know in ZF2 you only have to build a MIME multipart message and then use setBody() to that message, but in Zend 1.10 you must set either setBodyText() or setBodyHtml(). Is it possible to control how the MIME multipart message is created?