The content of this article is about resetting the password in PHP and sending it to the email (complete code). It has a certain reference value. Now I share it with you. Friends in need can refer to it.
<span style="font-family:Microsoft YaHei;"><span style="font-size:14px;">public function sendpass() { $email=$_POST["email"]; $n=M("member"); $pass=substr(md5(time()), 0, 6); $where["password"]=md5($pass); $arr=$n->where("email='$email'")->find(); if($arr) { $id=$arr["id"]; if($n->where("id=$id")->save($where)) { $mail = new \Think\SendMail(); $mail->setServer("****.163.com", "****@163.com", "****"); //设置smtp服务器 $mail->setFrom("****@163.com"); //设置发件人 $mail->setReceiver($arr["email"]); //设置收件人,多个收件人,调用多次 $mail->setCc("****@163.com"); //设置抄送,多个抄送,调用多次 </span></span><span style="font-family:Microsoft YaHei;"><span style="font-size:14px;"> $mail->setMailInfo("****-密码重置", "密码:<b>$pass</b>"); //设置邮件主题,内容 $mail->sendMail(); //发送 $this->assign("rs","alert('重置密码成功,请查看邮箱!');"); $this->display("pages:login"); } else { $this->assign("rs","alert('重置密码错误!邮箱不存在!');"); $this->display("pages:login"); } } else { $this->assign("rs","alert('重置密码错误,邮箱不存在!');"); $this->display("pages:login"); } }</span></span>
Related Recommended:
The above is the detailed content of PHP reset password and send to email (full code). For more information, please follow other related articles on the PHP Chinese website!