2

I'm trying to send email with inline images and attachments with Zend Framework 1.

$mail = new Zend_Mail();
$mail->setType(Zend_Mime::MULTIPART_MIXED);
$mail->setSubject('Message');
$mail->setFrom('user@example1.com', 'Example user #1');
$mail->addTo('user@example2.com', 'Example user #2');

And trying to make nested email, by this example.

message
  mainMultipart (content for message, subType="related")
    ->htmlAndTextBodyPart (bodyPart1 for mainMultipart)
      ->htmlAndTextMultipart (content for htmlAndTextBodyPart)
        ->htmlBodyPart (bodyPart1 for htmlAndTextMultipart)
          ->html (content for htmlBodyPart)
        ->textBodyPart (bodyPart2 for the htmlAndTextMultipart)
          ->text (content for textBodyPart)
    ->fileBodyPart1 (bodyPart2 for the mainMultipart)
      ->FileDataHandler (content for fileBodyPart1)

Small Example:

$html               = '<p>Hello</p>';
$bodyHtmlPart       = new Zend_Mime_Part($html);
$bodyHtmlPart->type = Zend_Mime::TYPE_HTML;

$bodyMsg            = new Zend_Mime_Message();
$bodyMsg->addPart($bodyHtmlPart);

// And other nesting.. ending with Zend_Mime_Message

Question:

How to set Zend_Mime_Message to Zend_Mail body? Below added couple Zend_Mail functions, not really helpful.

$mail->setBodyHtml( ? );
$mail->setBodyText( ? );

I tried to look at Zend_Mail_Message function, but look alike it only works with ZF2.

Community
  • 1
  • 1
Vaidas
  • 818
  • 9
  • 22

2 Answers2

2

What about

$mailObject->setParts($mimeMessageObject->getParts());

?

php-dev
  • 6,340
  • 4
  • 18
  • 37
0

For inline images here is a class someone wrote for it: http://davidnussio.wordpress.com/2008/09/21/inline-images-into-html-email-with-zend-framework/

If your wanting to send as an attachment, then its plain and simple from the docs:

$mail = new Zend_Mail();

$at = $mail->createAttachment($myImage);
$at->type        = 'image/gif';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding    = Zend_Mime::ENCODING_BASE64;
$at->filename    = 'test.gif';

$mail->send();

Notice how on both Zend's example and that class from the link both have the following set for the disposition.

Zend_Mime::DISPOSITION_INLINE;

Zend Docs: http://framework.zend.com/manual/1.12/en/zend.mail.attachments.html

Hope that helps.

alex
  • 582
  • 3
  • 7
  • Problem I'm facing: can't have inline image attachments and attached files displayed properly. That's why I'm doing `multipart MIME nesting`. Answer not really match question. – Vaidas May 16 '14 at 16:20
  • Well duh I know they aren't displaying properly, I didn't write this answer to help show you how to display bananas. – alex May 16 '14 at 16:22