// 邮箱找回密码
public function rest(){
return $this->fetch();
}
public function sendEmail(){
$data = input();
$username = $data['username'];
$map['user_name'] = $username;
$userInfo = db('users')->where($map)->find();
if($userInfo){
if($userInfo['email'] == $data['email']){
import('email.Smtp', EXTEND_PATH);
$smtpserver = "smtp.126.com";//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = "wpf8970510@126.com";//SMTP服务器的用户邮箱
$smtpemailto = $data['email'];
$smtpuser = "wpf8970510";//SMTP服务器的用户帐号(或填写new2008oh@126.com,这项有些邮箱需要完整的)
$smtppass = "你的授权码";//SMTP服务器的用户授权码(很多坑货写的是密码)
$mailtitle = "重置密码";//邮件主题
$mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件
$host = $_SERVER['HTTP_HOST'];
$key = md5(time());
$reset_url = "http://$host/index.php/api/Wpftest/restpass?email=$smtpemailto&key=$key";
$mailcontent = "请点击以下链接重置密码,以便激活您的账号:<a href='$reset_url'>$reset_url</a>";
//************************ 配置信息 ****************************
$smtp = new \Smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp->debug = true;//是否显示发送的调试信息
$smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);
}else{
exit('用户名和Email不匹配');
}
}else{
exit('用户名不存在');
}
}
public function restpass(){
$this->assign('email',input('email'));
return $this->fetch();
}
public function getpassword(){
$email = input('email');
$password = md5(md5(input('password')));
$res = db('users')->where('email',$email)->update(['password'=>$password]);
if($res){
exit('success');
}
}
//邮箱验证模板
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>邮箱验证</title>
</head>
<body>
<form action="sendEmail" method="post">
<p>用户名:<input type="text" name="username" /></p>
<p>邮 箱:<input type="text" name="email" /></p>
<p><input type="submit" value="提交" /></p>
</form>
</body>
</html>
// 重置密码模板
<!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>重置密码</title> </head> <body> <form action="getpassword" method="post"> <p>新密码:<input type="text" name="password" /></p> <input type="hidden" name="email" value="{$email}"/> <p><input type="submit" value="提交" /></p> </form> </body> </html>