email 发送邮箱修改密码
2016-07-12 09:55
549 查看
首先是 index.php
![](http://img.blog.csdn.net/20160712094622161?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> </head> <body> <h2>找回密码</h2> <p class="demo"></p> <form action=""> <table> <tr> <td>用户名:</td> <td><input type="text" id="username"/></td> </tr> <tr> <td>邮箱:</td> <td><input type="text" class="input" name="email" id="email"><span id="chkmsg"></span></td> </tr> <tr> <td><input type="button" class="btn" id="sub_btn" value="提 交"></td> <td></td> </tr> </table> </form> </body> </html> <script src="jq.js"></script> <script> $(function(){ $("#sub_btn").click(function(){ var username=$("#username").val(); var email = $("#email").val(); var preg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; //匹配Email if(email=='' || !preg.test(email)){ $("#chkmsg").html("请填写正确的邮箱!"); }else{ $("#sub_btn").attr("disabled","disabled").val('提交中..').css("cursor","default"); $.post("sendmail.php",{mail:email,username:username},function(msg){ // if(msg=="noreg"){ // $("#chkmsg").html("该邮箱尚未注册!"); // $("#sub_btn").removeAttr("disabled").val('提 交').css("cursor","pointer"); // }else{ $(".demo").html("<h3>"+msg+"</h3>"); // } }); } }); }) </script> 然后 sendmail.php
<?php include_once("connect.php");//连接数据库 include_once('class.phpmailer.php'); $username=$_POST['username']; $email = stripslashes(trim($_POST['mail'])); $sql = "select uid,username,pwd from `user` where `username`='$username'"; $re = $pdo->query($sql); $row =$re->fetch(PDO::FETCH_ASSOC); $getpasstime = time(); $uid = $row['uid']; $token = md5($uid.$row['username'].$row['pwd']);//组合验证码 $url = "http://localhost/xiaoer/zhoukao1/reset.php?email=".$email." &token=".$token;//构造URL $time = date('Y-m-d H:i'); //邮箱标题 $emailsubject = "找回密码"; //拼接邮箱内容 $emailbody= "亲爱的".$email.":<br/>您在".$time."提交了修改密码请求。请点击下面的链接重置密码 (按钮24小时内有效)。<br/><a href='".$url."'target='_blank'>".$url."</a>"; $result = sendmail($emailsubject,$emailbody,$username,$email); if($result==1){//邮件发送成功 $msg = '系统已向您的邮箱发送了一封邮件<br/>请登录到您的邮箱及时重置您的密码!'; //更新数据发送时间 $pdo->query("update `user` set `getpasstime`='$time' where uid='$uid '"); }else{ $msg = $result; } echo $msg; //} //发送邮件 function sendmail($emailsubject,$emailbody,$username,$email){ $mail= new PHPMailer(); /*服务器相关信息*/ // $mail->SmtpMail.SmtpServer = "127.0.0.1"; $mail->IsSMTP(); //设置使用SMTP服务器发送 $mail->SMTPAuth = true; //开启SMTP认证 $mail->Host = 'smtp.163.com'; //设置 SMTP 服务器,自己注册邮箱服务器地址 $mail->Username = ''; //发信人的邮箱名称 $mail->Password = ''; //发信人的邮箱密码 /*内容信息*/ $mail->IsHTML(true); //指定邮件格式为:html $mail->CharSet ="UTF-8"; //编码 $mail->From = ''; //发件人完整的邮箱名称 $mail->FromName = $username; //发信人署名 $mail->Subject = $emailsubject; //信的标题 $mail->MsgHTML($emailbody); //发信主体内容 //$mail->AddAttachment("15.jpg"); //附件 /*发送邮件*/ $mail->AddAddress($email); //收件人地址 //使用send函数进行发送 if($mail->Send()) { return true; } else { self::$error=$mail->ErrorInfo; return false; } } ?>reset.php
<?php header("content-type:text/html;charset=utf-8"); include_once("connect.php");//连接数据库 $token = stripslashes(trim($_GET['token'])); $email = stripslashes(trim($_GET['email'])); $sql = "select * from `user` where email='$email'"; $query = $pdo->query($sql); $row =$query->fetch(PDO::FETCH_ASSOC); if($row){ $pwd=$row['pwd']; $mt = md5($row['uid'].$row['username'].$row['pwd']); if($mt==$token){ $mydate=strtotime($row['getpasstime']); if(time()-$mydate>24*60*60){ $msg = '该链接已过期!'; }else{ //重置密码... 此处略过 //$msg =include_once('update.php'); } }else{ $msg = '无效的链接'; } }else{ $msg = '错误的链接!'; } echo $msg; ?>
相关文章推荐
- linker command failed with exit code 1 (use -v to see invocation)
- 【打CF,学算法——二星级】Codeforces 22B Bargaining Table(区域和)
- Installation error: INSTALL_FAILED_UPDATE_INCOMPATIBLE解决方法
- [Cloud Computing]Mechanisms: Failover System
- saiku2.x刷新缓存的方法
- Mybaits深入了解(三)----mybatis开发Dao的方法
- 自定义Canvas
- paint Canvas画笔、画布
- Web QQ API 分析
- HDU2057 A + B Again
- LeetCode 217. Contains Duplicate
- codeforces 690C3 C3. Brain Network (hard)(lca)
- Paint之函数大汇总
- codeforces 690C2 C2. Brain Network (medium)(bfs+树的直径)
- 【转】session setup failed: NT_STATUS_LOGON_FAILURE -- 不错
- codeforces 690C1 C1. Brain Network (easy)(水题)
- Splay 模板题 一 hdu 3487 play with chain
- 690C2Brain Network (medium)
- rsync: failed to set times on "/." (in ftp): Operation not permitted (1)
- poj1273 Drainage Ditches