params['fromEmail'] ?? ''; if (!$fromEmail) { throw new InvalidConfigException('Please specify fromEmail app in app params'); } return [$fromEmail => 'Ely.by Accounts']; } /** * @return array */ public function getParams(): array { return []; } /** * @param array|string $to see \yii\mail\MessageInterface::setTo to know the format. * * @throws \common\emails\exceptions\CannotSendEmailException */ public function send(array|string $to): void { if (!$this->createMessage($to)->send()) { throw new exceptions\CannotSendEmailException(); } } /** * @return string|array{ * html?: string, * text?: string, * } */ abstract protected function getView(): string|array; final protected function getMailer(): MailerInterface { return $this->mailer; } protected function createMessage($for): MessageInterface { return $this->getMailer() ->compose($this->getView(), $this->getParams()) ->setTo($for) ->setFrom($this->getFrom()) ->setSubject($this->getSubject()); } }