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


PHP YiiMailMessage::getSubject方法代码示例

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


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

示例1: send

 public function send(array $events)
 {
     $eventsCount = count($events);
     if ($eventsCount == 0) {
         return;
     }
     $mailer = Yii::app()->mailer;
     $mailer->init();
     for ($i = 0; $i < $eventsCount; $i++) {
         $curEvent = $events[$i];
         $mailAccount = $curEvent->eventType->mailAccount;
         $mailerTransport = $mailer->getTransport()->setHost($mailAccount->host);
         if ($mailAccount->getIsNeedAuthorize()) {
             //нужна авторизация на сервере
             $mailerTransport->setUsername($mailAccount->user_name)->setPassword($mailAccount->user_password);
         } else {
             $mailerTransport->setUsername(null)->setPassword(null);
         }
         $eventsProcess = $curEvent->getEventsProcess();
         $eventsProcessCount = count($eventsProcess);
         for ($k = 0; $k < $eventsProcessCount; $k++) {
             $curEventProcess = $eventsProcess[$k];
             $mailMessage = new YiiMailMessage();
             $mailMessage->setTo($curEventProcess->email);
             $mailMessage->setSubject($curEvent->subject);
             $messageContent = '';
             if ($curEvent->event_message === null) {
                 $ncEvent = new NotifierComponentEvent($this, $curEvent, $curEventProcess, $mailMessage);
                 $this->onEmptyMessage(new NotifierComponentEvent($this, $curEvent, $curEventProcess, $mailMessage));
                 if ($mailMessage->getBody() == null && empty($ncEvent->params['messageContent'])) {
                     $curEventProcess->saveAsSent();
                     continue;
                 } elseif (!empty($ncEvent->params['messageContent'])) {
                     $messageContent = $ncEvent->params['messageContent'];
                 }
             } else {
                 $messageContent = $curEvent->event_message;
             }
             if ($mailMessage->getFrom() == null) {
                 //если не указан отправитель, то берем из настроек аккаунта
                 if (!empty($mailAccount->from_name)) {
                     $mailMessage->setFrom(array($mailAccount->email_from => $mailAccount->from_name));
                 } else {
                     $mailMessage->setFrom($mailAccount->email_from);
                 }
             }
             //если тема не указана, то в качестве темы устанавливаем название типа события
             if ($mailMessage->getSubject() == null) {
                 $mailMessage->setSubject($curEvent->eventType->name);
             }
             //Если есть что прикреплять
             if (!empty($messageContent)) {
                 $eventFormat = $curEventProcess->eventSubscriber->eventFormat;
                 switch ($eventFormat->place) {
                     case NotifierEventFormat::PLACE_TEXT:
                         $mailMessage->setBody($messageContent, $eventFormat->name == NotifierEventFormat::TYPE_HTML ? 'text/html' : 'text/plain');
                         break;
                     case NotifierEventFormat::PLACE_ATTACHMENT:
                         $fileName = $eventFormat->file_name;
                         if ($curEventProcess->eventSubscriber->getIsArchiveAttachment()) {
                             //TODO Архивируем вложение
                         }
                         //TODO Добавляем файл в аттач
                         break;
                 }
             }
             if (!$this->onBeforeSend(new NotifierComponentEvent($this, $curEvent, $curEventProcess, $mailMessage))) {
                 continue;
             }
             $errorMessage = false;
             try {
                 if ($mailer->send($mailMessage, $failures)) {
                     $curEventProcess->saveAsSent();
                 } else {
                     $errorMessage = sprintf("Ошибка при отправке почты:\n %s", print_r($failures, true));
                 }
             } catch (Exception $e) {
                 $errorMessage = $e->getMessage();
             }
             if ($errorMessage) {
                 Yii::log($errorMessage, CLogger::LEVEL_ERROR, 'mail.notifier.send');
             }
         }
         // endfor $eventProcess
     }
     // endfor $events
 }
开发者ID:kot-ezhva,项目名称:ygin,代码行数:87,代码来源:Notifier.php


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