/** * Поиск пользователя по id. * * @return User|null User instance */ protected function getUser() { if ($this->_user === null) { $this->_user = User::find()->where(['id' => Yii::$app->user->identity->id])->status(User::STATUS_ACTIVE)->one(); } return $this->_user; }
/** * Send Email * * @param $email * @param $view * @param $subject * @param $content * * Command: php yii users/control/send-email [email] [view] [subject] [content] */ public function actionSendEmail($email, $view, $subject, $content = null) { $this->_user = User::find()->where('email = :email', [':email' => $email])->one(); if ($this->_user) { $mail = Yii::$app->getMailer(); $mail->viewPath = $this->mailViewPath; $send = $mail->compose($view, ['user' => $this->_user, 'content' => $content])->setFrom(Yii::$app->getMailer()->messageConfig['from'])->setTo($this->_user['email'])->setSubject($subject)->send(); if ($send) { $this->stdout("SUCESS" . PHP_EOL, Console::FG_GREEN); Yii::getLogger()->log('SUCCESS: E-MAIL: ' . $this->_user['email'] . ', view: ' . $view, Logger::LEVEL_INFO, 'users.send'); } else { $this->stdout("ERROR" . PHP_EOL, Console::FG_RED); Yii::getLogger()->log('ERROR: E-MAIL: ' . $this->_user['email'] . ', view: ' . $view, Logger::LEVEL_ERROR, 'users.send'); } } else { Yii::getLogger()->log('ERROR: send fail. DATA: ' . $email . ', ' . $view . ', ' . $subject, Logger::LEVEL_ERROR, 'users.send'); } }