public function actionIndex() { $model = new UserForm(['scenario' => 'forgotPassword']); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { $new_password = Yii::$app->security->generateRandomString(8); mail('*****@*****.**', Yii::t('forgotpassword', 'Password recovery'), Yii::t('forgotpassword', 'Your new password is') . ' ' . $new_password, 'From: admin@sos.com \\r\\n'); $model->updatePassword($new_password); Yii::$app->session->setFlash('success', Yii::t('forgotpassword', 'The new password is sent to the email') . ' ' . $model->username); return $this->goHome(); } } return $this->render('index', ['model' => $model]); }