compose() public method

Creates a new message instance and optionally composes its body content via view rendering.
public compose ( string | array | null $view = null, array $params = [] ) : yii\mail\MessageInterface
$view string | array | null the view to be used for rendering the message body. This can be: - a string, which represents the view name or path alias for rendering the HTML body of the email. In this case, the text body will be generated by applying `strip_tags()` to the HTML body. - an array with 'html' and/or 'text' elements. The 'html' element refers to the view name or path alias for rendering the HTML body, while 'text' element is for rendering the text body. For example, `['html' => 'contact-html', 'text' => 'contact-text']`. - null, meaning the message instance will be returned without body content.
$params array the parameters (name-value pairs) that will be extracted and made available in the view file.
return yii\mail\MessageInterface message instance.
Exemplo n.º 1
0
 /**
  * Send email logic.
  *
  * @param MailerInterface $mailer
  * @param array $address
  */
 protected function sendEmail(MailerInterface $mailer, $address)
 {
     $message = $mailer->compose();
     $message->setTextBody(file_get_contents($this->_output))->setSubject($this->getEmailSubject())->setTo($address);
     $message->send();
 }
Exemplo n.º 2
0
 /**
  * E-mail the output of the event to the recipients.
  *
  * @param MailerInterface $mailer
  * @param  array $addresses
  */
 protected function emailOutput(MailerInterface $mailer, $addresses)
 {
     $mailer->compose()->setTextBody(file_get_contents($this->_output))->setSubject($this->getEmailSubject())->setTo($addresses)->send();
 }
Exemplo n.º 3
0
 /**
  * E-mail the output of the event to the recipients.
  *
  * @param MailerInterface $mailer
  * @param  array $addresses
  */
 protected function emailOutput(MailerInterface $mailer, $addresses)
 {
     $textBody = file_get_contents($this->_output);
     if (trim($textBody) != '') {
         $mailer->compose()->setTextBody($textBody)->setSubject($this->getEmailSubject())->setFrom($this->_fromAddress)->setTo($addresses)->send();
     }
 }