如何在Yii2上设置重置密码功能?

时间:2016-11-06 02:13:37

标签: yii2

我有这个错误:"视图文件不存在:/var/www/html/myproject/frontend/views/common/mail/passwordResetToken-html.php"

这是位于frontend / models / PasswordResetRequestForm

的代码
return Yii::$app
    ->mailer
    ->compose(
        ['html' => '/common/mail/passwordResetToken-html', 
         'text' => '/common/mail/passwordResetToken-text'],
        ['user' => $user]
    )
    ->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])
    ->setTo($this->email)
    ->setSubject('Password reset for ' . Yii::$app->name)
    ->send();

1 个答案:

答案 0 :(得分:2)

您可能有错误的路径尝试普通邮件

return Yii::$app
    ->mailer
    ->compose(
        ['html' => '@common/mail/passwordResetToken-html', 
         'text' => '@common/mail/passwordResetToken-text'],
        ['user' => $user]
    )
    ->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])
    ->setTo($this->email)
    ->setSubject('Password reset for ' . Yii::$app->name)
    ->send();

总之,检查你的main.php或主要地方

 'components' => [
    .....
    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail', //  <<<<----------- this  entry  
         ....
        ......
        'transport' => [
           ....
        ],
    ],
  ],