Exemplo n.º 1
0
 public function __construct(array $options = array())
 {
     // @TODO make this multipart
     parent::__construct($options);
     $this->getHeaders()->addHeader(Header\ContentType::fromString('Content-Type: text/html; charset=UTF-8'));
     $this->setEncoding('UTF-8');
     $this->variables = new ViewVariables();
 }
Exemplo n.º 2
0
 public function testExtractsExtraInformationFromContentType()
 {
     $contentTypeHeader = ContentType::fromString('Content-Type: multipart/alternative; boundary="Apple-Mail=_1B852F10-F9C6-463D-AADD-CD503A5428DD"');
     $params = $contentTypeHeader->getParameters();
     $this->assertEquals($params, array('boundary' => 'Apple-Mail=_1B852F10-F9C6-463D-AADD-CD503A5428DD'));
 }
 public function __construct(array $options = array())
 {
     parent::__construct($options);
     $this->getHeaders()->addHeader(Header\ContentType::fromString('Content-Type: text/plain; charset=UTF-8'));
     $this->setEncoding('UTF-8');
 }
Exemplo n.º 4
0
 public function testContentTypeFromStringCreatesValidContentTypeHeader()
 {
     $contentTypeHeader = ContentType::fromString('Content-Type: xxx/yyy');
     $this->assertInstanceOf('Zend\\Mail\\Header\\HeaderInterface', $contentTypeHeader);
     $this->assertInstanceOf('Zend\\Mail\\Header\\ContentType', $contentTypeHeader);
 }
Exemplo n.º 5
0
 /**
  * @param       $subject
  * @param       $html
  * @param       $plain
  * @param array $options
  * @param array $receivers
  * @param array $attachments
  *
  * @return Mail\Message
  */
 protected function _assembleMailMessage($subject, $html, $plain, array $options, array $receivers, array $attachments = [])
 {
     $config = $this->_rendererConfig;
     $message = new Mail\Message();
     $message->setEncoding('UTF-8');
     // Sender
     if (isset($options['use_default_sender']) && $options['use_default_sender'] === true) {
         $fromEmail = isset($config['mail_from_email']) ? $config['mail_from_email'] : null;
         $fromName = isset($config['mail_from_name']) ? $config['mail_from_name'] : null;
     } else {
         $fromEmail = isset($options['sender_mail']) ? $options['sender_mail'] : null;
         $fromName = isset($options['sender_name']) ? $options['sender_name'] : null;
     }
     $addressListFrom = new Mail\AddressList();
     $addressListFrom->add(new Mail\Address($fromEmail, isset($fromName) ? $fromName : null));
     $message->setFrom($addressListFrom);
     // Receiver
     $addressListTo = new Mail\AddressList();
     foreach ($receivers as $receiver) {
         $recEmail = isset($config['email_receiver_override']) ? $config['email_receiver_override'] : $receiver[0];
         $recName = isset($receiver[1]) ? $receiver[1] : null;
         $addressListTo->add(new Mail\Address($recEmail, $recName));
     }
     $message->setTo($addressListTo);
     if (isset($config['mail_bcc']) && is_array($config['mail_bcc'])) {
         foreach ($config['mail_bcc'] as $bccAddress) {
             // Avoid sending email copy to "to" AND bcc
             $found = false;
             foreach ($message->getTo() as $to) {
                 if ($to->getEmail() == $bccAddress) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 $addressListBcc = new Mail\AddressList();
                 $addressListBcc->add(new Mail\Address($bccAddress));
                 $message->addBcc($addressListBcc);
             }
         }
     }
     if (isset($config['subject_prefix']) && $config['subject_prefix'] != '') {
         $subject = $config['subject_prefix'] . $subject;
     }
     $message->setSubject($subject);
     if (empty($attachments)) {
         $message->setBody($html);
         $contentType = Mail\Header\ContentType::fromString('Content-Type: text/html; charset=utf-8');
         $message->getHeaders()->addHeader($contentType);
         $contentTransferEncoding = Mail\Header\ContentTransferEncoding::fromString('Content-Transfer-Encoding: 8bit');
         $message->getHeaders()->addHeader($contentTransferEncoding);
     } else {
         $html = new Mime\Part($html);
         $html->type = Mime\Mime::TYPE_HTML;
         $html->charset = 'UTF-8';
         $html->disposition = Mime\Mime::DISPOSITION_INLINE;
         $html->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
         $body = new Mime\Message();
         $body->addPart($html);
         foreach ($attachments as $attachmentData) {
             if (isset($attachmentData['file_path']) && is_readable($attachmentData['file_path'])) {
                 $attachmentData['file_data'] = file_get_contents($attachmentData['file_path']);
             }
             if (isset($attachmentData['file_data']) && !empty($attachmentData['file_data'])) {
                 $attachment = new Mime\Part($attachmentData['file_data']);
                 $attachment->type = $attachmentData['mime_type'];
                 $attachment->filename = $attachmentData['name'];
                 $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
                 $attachment->encoding = Mime\Mime::ENCODING_BASE64;
                 $body->addPart($attachment);
             }
         }
         $message->setBody($body);
     }
     return $message;
 }