for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace terabytesoft\helpers;
use yii\base\Component;
use yii\mail\MailerInterface;
/**
* Class Mailer
*
**/
class Mailer extends Component
{
* @var \yii\mail\MessageInterface $emailConfig
*/
protected $emailConfig;
* sendMessage
public function sendMessage(
string $to,
string $subject,
array $options,
array $params,
MailerInterface $mailer
): bool {
if (isset(\Yii::$app->params['helper.mailer.viewpath'])) {
$mailer->viewPath = \Yii::$app->params['helper.mailer.viewpath'];
viewPath
yii\mail\MailerInterface
instanceof
}
$views = isset($options['views']) ? $options['views'] : [];
$this->emailConfig = $mailer
->compose($views, $params)
->setTo($to)
->setFrom(
[\Yii::$app->params['helper.mailer.sender'] => \Yii::$app->params['helper.mailer.sender.name']]
)
->setSubject($subject);
if (isset($options['replyTo'])) {
$this->emailConfig = $this->emailConfig
->setReplyTo($options['replyTo']);
if (isset($options['textBody'])) {
->setTextBody($options['textBody']);
if (isset($options['textHtml'])) {
->setHtmlBody($options['textHtml']);
return $mailer->send($this->emailConfig);