PHP+MySQL user registration send email activation account instance

Posted by iii on Fri, 15 Nov 2019 18:32:39 +0100

PHP+MySQL users register to send email to activate the account instance. The style of layui is simple and beautiful.

1. Register the email activation account and check whether the email has been registered.

2. Check whether the mailbox exists. Judge whether it is activated when the mailbox exists. If not, change the activation code and registration time. Send activation message when mailbox does not exist.

 

Mail configuration and comments

 1 $smtpserver = "smtp.exmail.qq.com"; //SMTP The server 
 2 $smtpserverport = 25; //SMTP Server port 
 3 $smtpusermail = "ruxi@faofao.cn"; //SMTP User mailbox for server 
 4 $smtpuser = "ruxi@faofao.cn"; //SMTP User account of the server 
 5 $smtppass = "*********"; //SMTP Authorization code of the server 
 6 $smtp = new Smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass); //Instantiate mail class    
 7 $emailtype = "HTML"; //Letter type, text:text;Webpage: HTML 
 8 $smtpemailto = $email; 
 9 $smtpemailfrom = $smtpusermail; 
10 $emailsubject = "User account activation"; 
11 $emailbody = "    "; 
12  $rs = $smtp->sendmail($smtpemailto, $smtpemailfrom, $emailsubject, $emailbody, $emailtype);

Activation verification

 1 if($num>=1){ 
 2     //More than one record exists 
 3     $jihuo = mysql_query("select * from fao_user where fao_email='$email'"); 
 4     if($row = mysql_fetch_array($jihuo)){ 
 5         $upstatus=$row['fao_status']; 
 6         $upid=$row['fao_id']; 
 7         } 
 8  
 9     if($upstatus==0){ 
10             //If the activation status is 0, it means it is not activated 
11             $updata = mysql_query("UPDATE fao_user SET fao_regtime='$regtime',fao_token='$token',fao_token_exptime='$token_exptime' WHERE fao_id='$upid'"); 
12             $retval = mysqli_query($updata); 
13             if(! $retval ){ 
14                   include_once("email.php"); 
15                   }else{ 
16                       ?><script type="text/javascript">alert("Registration failed, please submit an error and try later! Please log in to email to activate your account!");window.history.go(-1);</script><? 
17                     } 
18  
19                 }else{ 
20                  
21                     ?><script type="text/javascript">alert("Email has been registered. Please change another email account!");window.history.go(-1);</script><? 
22  
23                 } 
24                 exit; 
25                 }

Activation verification

 1 <? 
 2  
 3     }else{ 
 4     mysql_query("update fao_user set fao_status=1 where fao_id=".$row['fao_id']); 
 5     if(mysql_affected_rows($conn)!=1) die(0); 
 6     //        $msg = 'Activation succeeded!'; 
 7             ?><script type="text/javascript">alert("Your activation period has expired. Please re register your account and send activation email!");</script><? 
 8     } 
 9     }else{ 
10         ?><script type="text/javascript">alert("Successful activation!Skipping to landing page!");</script>if($row){ 
11     if($nowtime>$row['fao_token_exptime']){ //30min 
12         ?><script type="text/javascript">alert("Link failed!");</script><? 
13     }

Download this example: https://www.sucaihuo.com/php/2436.html

Topics: PHP Javascript MySQL