PHP+MySQL注册发送邮件激活账号完整版【原创

来源:https://www.sucaihuo.com/php/2436.html 2017-07-16 17:12浏览(3148) 收藏

1.注册发送邮件激活账号,同时检测邮箱是否已注册。2.检测邮箱是否存在,当邮箱存在时判断是否激活,若未激活,则更改激活码和注册时间。邮箱不存在时则发送激活邮件。
PHP+MySQL注册发送邮件激活账号完整版
分类:PHP > 其他 难易:初级
查看演示 下载资源 下载火币: 10 火币

样式用的layui就不贴了,表单代码如下。 另外:对于用户的输入要进行必要的前端验证,还应该有个要求用户重复输入密码的输入框,这里就简化了。

<form name="regform"  enctype="multipart/form-data" action="register.php" method="post" > 
    <input type="text" name="email"  placeholder="请输入邮箱账号,作为你的登陆账号" /> 
    <input type="password" name="password"  placeholder="密码由6-16位符号、字母、数字等组成" /> 
    <input type="text" name="username"  placeholder="昵称长度为3-8个字符" /> 
    <input type="reset" name="reset" id="reset" value="重置" /> 
    <input type="submit" name="submit" id="submit" value="提交" /> 
</form>

邮件配置及注释

$smtpserver = "smtp.exmail.qq.com"; //SMTP服务器
$smtpserverport = 25; //SMTP服务器端口
$smtpusermail = "ruxi@faofao.cn"; //SMTP服务器的用户邮箱
$smtpuser = "ruxi@faofao.cn"; //SMTP服务器的用户帐号
$smtppass = "*********"; //SMTP服务器的授权码
$smtp = new Smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass); //实例化邮件类   
$emailtype = "HTML"; //信件类型,文本:text;网页:HTML
$smtpemailto = $email;
$smtpemailfrom = $smtpusermail;
$emailsubject = "用户帐号激活";
$emailbody = "	";
 $rs = $smtp->sendmail($smtpemailto, $smtpemailfrom, $emailsubject, $emailbody, $emailtype);

注册验证

if($num>=1){
	//大于一条记录则存在
	$jihuo = mysql_query("select * from fao_user where fao_email='$email'");
	if($row = mysql_fetch_array($jihuo)){
		$upstatus=$row['fao_status'];
		$upid=$row['fao_id'];
		}

	if($upstatus==0){
			//激活状态为0,表示未激活
			$updata = mysql_query("UPDATE fao_user SET fao_regtime='$regtime',fao_token='$token',fao_token_exptime='$token_exptime' WHERE fao_id='$upid'");
			$retval = mysqli_query($updata);
			if(! $retval ){
			  	include_once("email.php");
			  	}else{
			  		?><script type="text/javascript">alert("注册失败,请提交错误,稍后尝试!请及时登录邮箱激活您的帐号!");window.history.go(-1);</script><?
					}

				}else{
				
					?><script type="text/javascript">alert("邮箱已被注册,请更换其他的邮箱账号!");window.history.go(-1);</script><?

				}
				exit;
				}

激活验证

if($row){
	if($nowtime>$row['fao_token_exptime']){ //30min
		?><script type="text/javascript">alert("您的激活有效期已过,请重新注册您的帐号发送激活邮件!");</script><?

	}else{
	mysql_query("update fao_user set fao_status=1 where fao_id=".$row['fao_id']);
	if(mysql_affected_rows($conn)!=1) die(0);
	//		$msg = '激活成功!';
			?><script type="text/javascript">alert("激活成功!正在跳转到登录页!");</script><?
	}
	}else{
		?><script type="text/javascript">alert("链接已失效!");</script><?
	}
声明:本文为原创文章,如需转载,请注明来源sucaihuo.com并保留原文链接:https://www.sucaihuo.com/php/2436.html
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2