public function testMultiPart() { $msg = new Mime\Message(); // No Parts $this->assertFalse($msg->isMultiPart()); }
/** * Sends a mixed message via email * @param string[] $message * @param string[] $templates * @param string[] $variables * @return $this */ public function sendMixedMessage(array $message, array $templates, array $variables = []) { //create the message $mailMessage = $this->createMessage($message); //render the templates $contentMimeMessage = new MimeMessage(); foreach ($templates as $mimeType => $template) { //render the template $viewContent = $this->renderTemplate($template, $variables); //add the template to the message $mimePart = new MimePart($viewContent); $mimePart->type = $mimeType; $contentMimeMessage->addPart($mimePart); } //combine the alternative content into a single mime part if ($contentMimeMessage->isMultiPart()) { $contentMimePart = new MimePart($contentMimeMessage->generateMessage()); $contentMimePart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $contentMimeMessage->getMime()->boundary() . '"'; $contentMimeParts = [$contentMimePart]; } else { $contentMimeParts = $contentMimeMessage->getParts(); } //order the content before any attachments $finalMimeMessage = new MimeMessage(); $finalMimeMessage->setParts(array_merge($contentMimeParts, $mailMessage->getBody()->getParts())); $mailMessage->setBody($finalMimeMessage); //let the client choose which part to display if ($mailMessage->getBody()->isMultiPart()) { $mailMessage->getHeaders()->get('content-type')->setType('multipart/mixed'); } //send the message return $this->sendMessage($mailMessage); }