예제 #1
0
 public function testToAddressListLivesInHeaders()
 {
     $this->message->addTo('*****@*****.**');
     $to = $this->message->getTo();
     $headers = $this->message->getHeaders();
     $this->assertInstanceOf('Zend\\Mail\\Headers', $headers);
     $this->assertTrue($headers->has('to'));
     $header = $headers->get('to');
     $this->assertSame($header->getAddressList(), $to);
 }
예제 #2
0
파일: Smtp.php 프로젝트: Baft/Zend-Form
 /**
  * Prepare array of email address recipients
  *
  * @param  Message $message
  * @return array
  */
 protected function prepareRecipients(Message $message)
 {
     $recipients = array();
     foreach ($message->getTo() as $address) {
         $recipients[] = $address->getEmail();
     }
     foreach ($message->getCc() as $address) {
         $recipients[] = $address->getEmail();
     }
     foreach ($message->getBcc() as $address) {
         $recipients[] = $address->getEmail();
     }
     $recipients = array_unique($recipients);
     return $recipients;
 }
예제 #3
0
 /**
  * Prepare array of email address recipients
  *
  * @param  Message $message
  * @return array
  */
 protected function prepareRecipients(Message $message)
 {
     if ($this->getEnvelope() && $this->getEnvelope()->getTo()) {
         return (array) $this->getEnvelope()->getTo();
     }
     $recipients = [];
     foreach ($message->getTo() as $address) {
         $recipients[] = $address->getEmail();
     }
     foreach ($message->getCc() as $address) {
         $recipients[] = $address->getEmail();
     }
     foreach ($message->getBcc() as $address) {
         $recipients[] = $address->getEmail();
     }
     $recipients = array_unique($recipients);
     return $recipients;
 }
 /**
  * @param Message $message
  * @return bool
  */
 public function send(Message $message)
 {
     $this->email->addTo($message->getTo()->current()->getEmail(), $message->getTo()->current()->getName())->setFrom($message->getFrom()->current()->getEmail(), $message->getFrom()->current()->getName())->setSubject($message->getSubject())->setHtml($message->getBodyText());
     $this->sendGrid->send($this->email);
     return true;
 }
예제 #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;
 }
예제 #6
0
 /**
  * Create `Mandrill message` from `ZF message`.
  *
  * @param ZendMessage $zfMessage
  *
  * @return Message
  */
 public static function convertZFMail(ZendMessage $zfMessage)
 {
     $mandrillMessage = new self();
     // GET HTML MIME PART
     $messageHtmlPart = $messageTextPart = null;
     $mimeParts = $zfMessage->getBody()->getParts();
     foreach ($mimeParts as $mimePart) {
         switch ($mimePart->getType()) {
             case ZendMime::TYPE_HTML:
                 $messageHtmlPart = $mimePart->getContent();
                 break;
             case ZendMime::TYPE_TEXT:
                 $messageTextPart = $mimePart->getContent();
                 break;
         }
     }
     // text part
     if ($messageTextPart !== null) {
         $mandrillMessage->text = $messageTextPart;
     }
     // html part
     if ($messageHtmlPart !== null) {
         $mandrillMessage->html = $messageHtmlPart;
     }
     // subject
     if ($zfMessage->getSubject() !== null) {
         $mandrillMessage->subject = $zfMessage->getSubject();
     }
     // from
     if ($zfMessage->getFrom()->count()) {
         $mandrillMessage->from_email = $zfMessage->getFrom()->current()->getEmail();
         $mandrillMessage->from_name = $zfMessage->getFrom()->current()->getName();
     }
     // reply-to
     if ($zfMessage->getReplyTo()->count()) {
         $mandrillMessage->headers = ['Reply-To' => $zfMessage->getReplyTo()->current()->getEmail()];
     }
     // to
     if ($zfMessage->getTo()->count()) {
         foreach ($zfMessage->getTo() as $to) {
             $mandrillMessage->addRecipient(new Recipient($to->getEmail(), null, Recipient::RECIPIENT_TYPE_TO));
         }
     }
     // cc
     if ($zfMessage->getCc()->count()) {
         foreach ($zfMessage->getCc() as $cc) {
             $mandrillMessage->addRecipient(new Recipient($cc->getEmail(), null, Recipient::RECIPIENT_TYPE_CC));
         }
     }
     // bcc
     if ($zfMessage->getBcc()->count()) {
         foreach ($zfMessage->getBcc() as $bcc) {
             $mandrillMessage->addRecipient(new Recipient($bcc->getEmail(), null, Recipient::RECIPIENT_TYPE_BCC));
         }
     }
     return $mandrillMessage;
 }
예제 #7
0
 /**
  * Prepares list of all mail recipients
  *
  * @param Message $message
  * @return array
  */
 private function prepareAddressList(Message $message)
 {
     $addressList = array();
     foreach ($message->getTo() as $address) {
         $addressList[] = $address->getEmail();
     }
     foreach ($message->getCc() as $address) {
         $addressList[] = $address->getEmail();
     }
     foreach ($message->getBcc() as $address) {
         $addressList[] = $address->getEmail();
     }
     return $addressList;
 }