How to implement email activation in Yii framework

不言
Release: 2023-03-25 11:16:01
Original
1225 people have browsed it

This article mainly introduces the method of Yii framework to realize mailbox activation. The activation function of digital signature is realized by sending emails based on mailbox. Friends in need can refer to the following.

The example of this article tells the Yii framework to realize mailbox activation. method. Share it with everyone for your reference, the details are as follows:

Controller:

//发送邮箱,激活账号
public function actionEmail()
{
    $email=Yii::$app->request->get('email');
    //数字签名
    $em_1=md5($email);
    //邮箱发送
    $mail= Yii::$app->mailer->compose();
    $mail->setTo($email);
    $mail->setSubject("激活邮箱");
    //发布可以带html标签的文本
    $mail->setHtmlBody("<a href=&#39;http://www.small2.com/backend/web/index.php?r=login/live&em_1=".$em_1."&email=".$email."&#39;>点击此链接</a>");
    if($mail->send())
      echo "success";
    else
      echo "false";
    die(); //邮箱发送ok
}
//激活账号
public function actionLive()
{
   $email=Yii::$app->request->get(&#39;email&#39;);
   $em_1=Yii::$app->request->get(&#39;em_1&#39;);
   //echo $em_1;die;
   $em_2=md5($email);
   //echo $em_2;die;
   if($em_1==$em_2)
   {
     $res=Yii::$app->db;
     $data=$res->createCommand()->update("login",["status"=>1],["email"=>$email])->execute();
     if($data)
     {
      echo "<script>alert(&#39;激活成功,可登录&#39;);location.href=&#39;index.php?r=login/login&#39;</script>";
     }
     else
     {
       echo "<script>alert(&#39;激活失败&#39;);location.href=&#39;index.php?r=login/login&#39;</script>";
     }
   }
   else
   {
     echo "<script>alert(&#39;参数错误,重新激活&#39;);location.href=&#39;index.php?r=login/login&#39;</script>";
   }
}
Copy after login

Principle: (The original default after registration There is status=0, which can be changed to 1 after activation before logging in.)

Related recommendations:

Yii2 framework implements login and logout And automatic login function

Yii2 framework implements a simple method to share reversible encryption

##

The above is the detailed content of How to implement email activation in Yii framework. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template