portal.mkgtu.ru/common/commands/handler/SendEmailHandler.php

35 lines
783 B
PHP
Raw Permalink Normal View History

2024-03-28 09:51:45 +03:00
<?php
namespace common\commands\handler;
use trntv\tactician\base\BaseHandler;
use yii\swiftmailer\Message;
class SendEmailHandler extends BaseHandler
{
public function handle($command)
{
if (!$command->body) {
$message = \Yii::$app->mailer->compose($command->view, $command->params);
} else {
$message = new Message();
if ($command->isHtml()) {
$message->setHtmlBody($command->body);
} else {
$message->setTextBody($command->body);
}
}
$message->setFrom($command->from);
$message->setTo($command->to ?: \Yii::$app->params['robotEmail']);
$message->setSubject($command->subject);
return $message->send();
}
}