2017-07-18 188 views
1
public function actionRequestPasswordReset() 
{ 
$model = new UserSignup(); 
if ($model->load(Yii::$app->request->post())) { 
$email = $model->email; 
$row = UserSignup::find()->where(['email' => $email])->exists();  
if($row != 1) 
{ 
Yii::$app->session->setFlash('error', 'User does not exist.'); 
} 
else{ 
$user = UserSignup::find()->where([ 
'email'=>$model->email 
])->one(); 
$randnkey = rand(); 
if(!empty($user)){ 
$template=" <a href=''> click here to verify your email address.</p> 
Regards, 
The NaijaLoving App Team"; 
$email = \Yii::$app->mailer->compose() 
->setTo($user->email) 
//->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' 
robot']) 
->setFrom("[email protected]") 
//->setSubject('Signup Confirmation')->setTextBody("Click this link ") 
->setHtmlBody(
"<table width='100%' border='0' cellpadding='0' cellspacing='0'> 
<tbody> 
<tr> 
<td style='background:#065e52;'> 
<img src='/naija_loving/frontend/web/image/logo.png'/> 
</tr> 
<tr> 
<td> 
<div class=email-area style='margin-top:20px;'> 
<div class='container email-box' style='background:#E3E3E3; padding:40px;'> 
<div class='email-prgp'> 
<p>Hi ".$user->username.",</p> 
<p>Your Username is ".$user->username." and to reset Password click on below 
link 
</p>".\yii\helpers\Html::a('confirm',Yii::$app->urlManager- 
>createAbsoluteUrl(['remail/remail','id'=>$user->u_id,'key'=>$randnkey]))." 
</p> 
<br/></div> 
<div class='lowr-email-prgph' style='margin-top: 20px;box-sizing: border- 
box;'> 
<p>Regards,<br>The NaijaLoving App Team</p></div></div></td></tr><tr><td> 
<div class='email-footer-box' style='margin:0 auto; text-align:center; 
background:#065e52; padding:10px;color:#fff;'><p style='line-height:23px;'> 
<a href='#' style='color:aqua'>[email protected]</a><br>Follow 
us<br>fb twitter youtube</p></div></td></tr></tbody></table>")->send(); 
if($email){ 
Yii::$app->session->setFlash('success',$user->username); 
} 
} else { 
Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset 
password for the provided email address.'); 
} 
} 
} 
return $this->render('requestPasswordResetToken', [ 
'model' => $model, 
]); 
} 

這個代碼是重置密碼鏈接我要上按一下按鈕重定向到 remail/remail ...但它重定向到主機/網站/登錄,是什麼東西 錯誤的代碼,我寫了一些自定義代碼發送電子郵件想用URL發送電子郵件,這是工作,但它重定向我到另一個網址,即主機/項目名稱/網站/登錄

+0

查看您的RemailController中是否存在accessControl過濾器,只允許記錄用戶執行每個操作。 – Bizley

+0

沒有這是忘記密碼時忘記密碼的過程它重定向重置密碼爲它你必須寫電子郵件,這將發送電子郵件到您的電子郵件帳戶,然後提供的鏈接將重定向到remail這個鏈接是不會重定向到所需路徑 – shikha

+0

您可以發佈控制器代碼請參閱 – Burrito

回答

0

我的第一個建議你使用郵件模板發送郵件。這種方式不是很好的做法。 創建錨標籤HREF可變即

$verifyLink = Yii::$app->urlManager->createAbsoluteUrl(['/remail/remail', 
'id'=>$user->u_id,'key'=>$randnkey]); 

然後用target = "_blank"在錨標籤href屬性使用此變量。

相關問題