Commit e3292c95 by Alexander Makarov

Advanced application template now uses mailer component instead of mail() function

parent d829dbb2
...@@ -15,6 +15,7 @@ return [ ...@@ -15,6 +15,7 @@ return [
'components.mail' => [ 'components.mail' => [
'class' => 'yii\swiftmailer\Mailer', 'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mails',
], ],
'components.db' => [ 'components.db' => [
......
...@@ -159,17 +159,11 @@ class SiteController extends Controller ...@@ -159,17 +159,11 @@ class SiteController extends Controller
$user->password_reset_token = Security::generateRandomKey(); $user->password_reset_token = Security::generateRandomKey();
if ($user->save(false)) { if ($user->save(false)) {
// todo: refactor it with mail component. pay attention to the arrangement of mail view files return \Yii::$app->mail->compose('passwordResetToken', ['user' => $user])
$fromEmail = \Yii::$app->params['supportEmail']; ->from([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
$name = '=?UTF-8?B?' . base64_encode(\Yii::$app->name . ' robot') . '?='; ->to($email)
$subject = '=?UTF-8?B?' . base64_encode('Password reset for ' . \Yii::$app->name) . '?='; ->subject('Password reset for ' . \Yii::$app->name)
$body = $this->renderPartial('/emails/passwordResetToken', [ ->send();
'user' => $user,
]);
$headers = "From: $name <{$fromEmail}>\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8";
return mail($email, $subject, $body, $headers);
} }
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment