示例#1
0
 /**
  * @param \DotBlue\Mandrill\Message $message
  * @param \Nette\Mail\Message $originalMessage
  */
 private function setAttachments(\DotBlue\Mandrill\Message $message, \Nette\Mail\Message $originalMessage)
 {
     // Dirty trick
     $stealAttachments = \Closure::bind(function () {
         return $this->attachments;
     }, $originalMessage, $originalMessage);
     foreach ($stealAttachments() as $attachment) {
         $name = $this->parseAttachmentName($attachment);
         $type = $attachment->getHeader('Content-Type');
         $content = $attachment->getBody();
         $message->addAttachment(new \DotBlue\Mandrill\Attachment($name, $content, $type));
     }
 }
示例#2
0
 /**
  * @param array $to
  * @param string $fromEmail
  * @param string $fromName
  * @param string $subject
  * @param string $body
  * @param string $contentType
  * @param array $cc
  * @param array $bcc
  * @return mixed
  */
 function send(array $to, $fromEmail, $fromName, $subject, $body, $contentType = 'text/html', $cc = [], $bcc = [])
 {
     $message = new Message();
     $message->setSubject($subject)->setFrom($fromEmail, $fromName);
     if ($contentType === 'text/html') {
         $message->setHtml($body)->setText(strip_tags($body));
     } else {
         $message->setText($body);
     }
     foreach (['to' => 'addTo', 'cc' => 'addCc', 'bcc' => 'addBcc'] as $type => $method) {
         foreach (${$type} as $item) {
             if (is_array($item)) {
                 $message->{$method}($item['email'], $item['name']);
             } else {
                 $message->{$method}($item);
             }
         }
     }
     $this->getMandrill()->send($message);
 }