A mailer should mainly support creating and sending [[MessageInterface|mail messages]]. It should
also support composition of the message body through the view rendering mechanism. For example,
php
Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
->setFrom('from@domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send();
/** * 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(); }
/** * 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(); }
/** * 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(); } }