Jan Beeck
Jan Beeck

Reputation: 315

How do I setup the reset password function on Yii2?

I have this error: "The view file does not exist: /var/www/html/myproject/frontend/views/common/mail/passwordResetToken-html.php"

This is the code located at 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();

Upvotes: 1

Views: 814

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133380

Could be you have the wrong path for common mail try

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();

And over all check if your main.php or main-local you have

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

Upvotes: 2

Related Questions