emailzend-frameworkzend-mail

Set Zend_Mime_Message as Zend_Mail body


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.


Solution

  • What about

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

    ?