Home  >  Article  >  Backend Development  >  PHP reset password and send to email (full code)

PHP reset password and send to email (full code)

不言
不言Original
2018-04-16 10:00:512484browse

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=&#39;$email&#39;")->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(&#39;重置密码成功,请查看邮箱!&#39;);");
	        $this->display("pages:login");
            }
            else
            {
            $this->assign("rs","alert(&#39;重置密码错误!邮箱不存在!&#39;);");
	        $this->display("pages:login");
            }  
        }
         else 
         {
            $this->assign("rs","alert(&#39;重置密码错误,邮箱不存在!&#39;);");
	        $this->display("pages:login");
         }
    }</span></span>

Related Recommended:

Timeline development in php



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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn