By default, BaseMessage::send will use the "mail" application component to send the current message. The "mail" application component should be a mailer instance implementing MailerInterface.
См. также: BaseMailer
С версии: 2.0
Автор: Paul Klimov (klimov.paul@gmail.com)
Наследование: extends yii\base\Object, implements yii\mail\MessageInterface
Пример #1
0
 public function init()
 {
     parent::init();
     $this->messageBuilder = new MessageBuilder();
 }
 /**
  * Get the HTML part from the email.
  * 
  * This is a current restriction since the BaseMessage class doesn't provide
  * method to get the rendered HTML.
  * 
  * This only works in \yii\swiftmailer\Message.
  * 
  * @param \yii\mail\BaseMessage $message
  * @return string|null the HTML string or null if not found.
  */
 private static function getHtmlBody($message)
 {
     if ($message instanceof \yii\swiftmailer\Message) {
         $swiftMessage = $message->getSwiftMessage();
         $r = new \ReflectionObject($swiftMessage);
         $parentClassThatHasBody = $r->getParentClass()->getParentClass()->getParentClass();
         //\Swift_Mime_SimpleMimeEntity
         $body = $parentClassThatHasBody->getProperty('_immediateChildren');
         $body->setAccessible(true);
         $children = $body->getValue($swiftMessage);
         foreach ($children as $child) {
             if ($child instanceof \Swift_MimePart && $child->getContentType() == 'text/html') {
                 return $child->getBody();
             }
         }
     }
     return null;
 }