PHP 重置密码并发送至邮箱 【完整代码】

时间:2022-09-17 20:42:00
<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>