当前位置: 首页>>代码示例>>PHP>>正文


PHP Message::getTemplate方法代码示例

本文整理汇总了PHP中Zend\Mail\Message::getTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::getTemplate方法的具体用法?PHP Message::getTemplate怎么用?PHP Message::getTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Mail\Message的用法示例。


在下文中一共展示了Message::getTemplate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parseMessage

 /**
  * @param  Message       $message
  * @param  DateTime|null $sendAt
  * @throws Exception\RuntimeException
  * @return array
  */
 private function parseMessage(Message $message, DateTime $sendAt = null)
 {
     $hasTemplate = $message instanceof MandrillMessage && null !== $message->getTemplate();
     $from = $message->getFrom();
     if ($hasTemplate && count($from) > 1 || !$hasTemplate && count($from) !== 1) {
         throw new Exception\RuntimeException('Mandrill API requires exactly one from sender (or none if send with a template)');
     }
     $from = $from->rewind();
     $parameters['message'] = array('subject' => $message->getSubject(), 'text' => $this->extractText($message), 'html' => $this->extractHtml($message), 'from_email' => $from ? $from->getEmail() : '', 'from_name' => $from ? $from->getName() : '');
     foreach ($message->getTo() as $to) {
         $parameters['message']['to'][] = array('email' => $to->getEmail(), 'name' => $to->getName(), 'type' => 'to');
     }
     foreach ($message->getCc() as $cc) {
         $parameters['message']['to'][] = array('email' => $cc->getEmail(), 'name' => $cc->getName(), 'type' => 'cc');
     }
     foreach ($message->getBcc() as $bcc) {
         $parameters['message']['to'][] = array('email' => $bcc->getEmail(), 'name' => $bcc->getName(), 'type' => 'bcc');
     }
     $replyTo = $message->getReplyTo();
     if (count($replyTo) > 1) {
         throw new Exception\RuntimeException('Mandrill has only support for one Reply-To address');
     } elseif (count($replyTo)) {
         $parameters['message']['headers']['Reply-To'] = $replyTo->rewind()->toString();
     }
     if ($message instanceof MandrillMessage) {
         if ($hasTemplate) {
             $parameters['template_name'] = $message->getTemplate();
             foreach ($message->getTemplateContent() as $key => $value) {
                 $parameters['template_content'][] = array('name' => $key, 'content' => $value);
             }
             // Currently, Mandrill API requires a content for template_content, even if it is an
             // empty array
             if (!isset($parameters['template_content'])) {
                 $parameters['template_content'] = array();
             }
         }
         foreach ($message->getGlobalVariables() as $key => $value) {
             $parameters['message']['global_merge_vars'][] = array('name' => $key, 'content' => $value);
         }
         foreach ($message->getVariables() as $recipient => $variables) {
             $recipientVariables = array();
             foreach ($variables as $key => $value) {
                 $recipientVariables[] = array('name' => $key, 'content' => $value);
             }
             $parameters['message']['merge_vars'][] = array('rcpt' => $recipient, 'vars' => $recipientVariables);
         }
         $parameters['message']['metadata'] = $message->getGlobalMetadata();
         foreach ($message->getMetadata() as $recipient => $variables) {
             $parameters['message']['recipient_metadata'][] = array('rcpt' => $recipient, 'values' => $variables);
         }
         foreach ($message->getOptions() as $key => $value) {
             $parameters['message'][$key] = $value;
         }
         foreach ($message->getTags() as $tag) {
             $parameters['message']['tags'][] = $tag;
         }
         foreach ($message->getImages() as $image) {
             $parameters['message']['images'][] = array('type' => $image->type, 'name' => $image->filename, 'content' => base64_encode($image->getRawContent()));
         }
     }
     $attachments = $this->extractAttachments($message);
     foreach ($attachments as $attachment) {
         $parameters['message']['attachments'][] = array('type' => $attachment->type, 'name' => $attachment->filename, 'content' => base64_encode($attachment->getRawContent()));
     }
     if (null !== $sendAt) {
         // Mandrill needs to have date in UTC, using this format
         $sendAt->setTimezone(new DateTimeZone('UTC'));
         $parameters['send_at'] = $sendAt->format('Y-m-d H:i:s');
     }
     return $parameters;
 }
开发者ID:roelvanduijnhoven,项目名称:SlmMail,代码行数:77,代码来源:MandrillService.php


注:本文中的Zend\Mail\Message::getTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。