我设法通过以下方式解决了这个问题。我在 UserController 中的 actionDelete 是:
public function actionDelete($id) {
$model = $this->loadModel($id);
$deletionUrl= Yii::app()->createAbsoluteUrl('user/confirm',array('aHash'=>$model->aHash));
$message = new YiiMailer();
$message->setView('contact');
$message->setBody($deletionUrl);
$message->setData(array('message' => '
You have received this email because you requested a deletion of your account.
If you did not make this request, please disregard this
email. You do not need to unsubscribe or take any further action.
</br>
<hr>
We require that you confirm your request to ensure that
the request made was correct. This protects against
unwanted spam and malicious abuse.
To confirm deletion of your account, simply click on the following link:
'.$deletionUrl.' <br> <br>
(Some email client users may need to copy and paste the link into your web
browser).','name' => 'yourname@123.com', 'description' => 'Please click on the link below in order to confirm your request:'));
$message->setLayout('mail');
$message->IsSMTP();
$message->setSubject ('Request for account deletion');
$message->Host = 'smtp.123.com';
$message->SMTPAuth = true;
$message->Username = 'yourname@123.com';
$message->Password = 'yourpassword';
$message->setFrom('yourname@123.com', 'yourname');
$message->setTo($model->aEmail);
if ( $message->send())
{
$this->render ('removeuser');
}
}
我在 UserController 中的 actionConfirm():
public function actionConfirm ()
{
$model = User::model()->findByAttributes(array('aHash' => $_GET['aHash']));
if ($model === null)
throw new CHttpException(404, 'Not found');
else
{
$this->loadModel($model->aUserID)->delete();
$model->save();
$this->render('afterdelete');
}
}