public function send(SmtpTransport $transport = null, Message $message, array $attachments = array()) { if ($transport == null) { $transport = new Sendmail(); } $content = $message->getBody(); $parts = $attachments; $parts = array(); $bodyMessage = new \Zend\Mime\Message(); $multiPartContentMessage = new \Zend\Mime\Message(); $text = new Part(html_entity_decode(strip_tags(str_replace("<br />", "\n", $content)))); $text->type = "text/plain"; $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $text->charset = 'UTF-8'; $multiPartContentMessage->addPart($text); $html = new Part($content); $html->type = Mime::TYPE_HTML; $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $html->charset = 'utf-8'; $multiPartContentMessage->addPart($html); $multiPartContentMimePart = new Part($multiPartContentMessage->generateMessage()); $multiPartContentMimePart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $multiPartContentMessage->getMime()->boundary() . '"'; $bodyMessage->addPart($multiPartContentMimePart); foreach ($attachments as $attachment) { $bodyMessage->addPart($attachment); } $message->setBody($bodyMessage); $message->setEncoding("UTF-8"); $transport->send($message); }
/** * Creates a mail message container of the given type for the mime parts. * * @param Zend\Mime\Part[] $parts List of mime parts that should be included in the container * @param string $type Mime type, e.g. "multipart/related" or "multipart/alternative" * @return \Zend\Mime\Part Container mime object */ protected function createContainer(array $parts, $type) { $msg = new \Zend\Mime\Message(); $msg->setParts($parts); $part = new \Zend\Mime\Part($msg->generateMessage()); $part->encoding = \Zend\Mime\Mime::ENCODING_8BIT; $part->boundary = $msg->getMime()->boundary(); $part->disposition = null; $part->charset = null; $part->type = $type; return $part; }
/** * Create a email based on it's theme an params * * @param string $address * @param string $name * @throws Exception * @return \Zend\Mail\Message */ protected function _constructEmail($address, $name) { $content = $this->_template->render(); if ('' == $this->_replyTo) { $this->_replyTo = $this->_template->getTestament()->getReplyTo(); } if ('' == $this->_fromName) { $this->_fromName = $this->_template->getTestament()->getFromName(); } if ('' == $this->_fromAddress) { $this->_fromAddress = $this->_template->getTestament()->getFromAddress(); } if ('' == $this->_subject) { $this->_subject = $this->_template->getTestament()->getFromAddress(); } $contentParts = array(); $partText = new Part($content->getText()); $partText->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $partText->type = Mime::TYPE_TEXT; $contentParts[] = $partText; $partHtml = new Part($content->getHtml()); $partHtml->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $partHtml->type = Mime::TYPE_HTML; $partHtml->charset = 'UTF-8'; $contentParts[] = $partHtml; $alternatives = new \Zend\Mime\Message(); $alternatives->setParts($contentParts); $alternativesPart = new Part($alternatives->generateMessage()); $alternativesPart->type = "multipart/alternative; boundary=\"" . $alternatives->getMime()->boundary() . "\""; $body = new \Zend\Mime\Message(); $body->addPart($alternativesPart); foreach ($this->_attachments as $attachmentSrc) { $attachment = new Part(fopen($attachmentSrc['filelocation'], 'r')); $attachment->filename = $attachmentSrc['filename']; $attachment->encoding = Mime::ENCODING_BASE64; $attachment->type = Mime::DISPOSITION_ATTACHMENT; $attachment->disposition = true; $body->addPart($attachment); } $subject = $this->_subject; foreach ($this->_variables as $name => $variable) { $subject = str_replace('{{:' . $name . ':}}', $variable, $subject); } $message = new Message(); $message->setSubject($subject); $message->setFrom($this->_fromAddress, $this->_fromName); if ($this->_replyTo) { $message->setReplyTo($this->_replyTo); } $message->setBody($body); $message->setTo($address, $name); $message->setEncoding("UTF-8"); return $message; }
public function send(Message $message, array $attachments = array()) { if ($this->getConfiguration()->getSendAllMailsToBcc() !== null) { $message->addBcc($this->getConfiguration()->getSendAllMailsToBcc()); } if ($this->getConfiguration()->getSendAllMailsTo() != null) { $message->setTo($this->getConfiguration()->getSendAllMailsTo()); } $content = $message->getBody(); $bodyMessage = new \Zend\Mime\Message(); $multiPartContentMessage = new \Zend\Mime\Message(); $text = new Part(strip_tags($content)); $text->type = Mime::TYPE_TEXT; $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $multiPartContentMessage->addPart($text); $html = new Part($content); $html->type = Mime::TYPE_HTML; $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $html->charset = 'utf-8'; $multiPartContentMessage->addPart($html); $multiPartContentMimePart = new Part($multiPartContentMessage->generateMessage()); $multiPartContentMimePart->charset = 'UTF-8'; $multiPartContentMimePart->type = 'multipart/alternative'; $multiPartContentMimePart->boundary = $multiPartContentMessage->getMime()->boundary(); $bodyMessage->addPart($multiPartContentMimePart); foreach ($attachments as $attachment) { $bodyMessage->addPart($attachment); } $message->setBody($bodyMessage); $message->setEncoding("UTF-8"); $this->transport->send($message); }