大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
//找回密码
public function reset(){
if(IS_POST){
$username=I(\'post.username\');
$email=I(\'post.email\');
//查询账号是否存在
$info= M(\'member\')->where(array(\'username\'=>$username))->field(\'id,email,username,password\')->find();
if($info[\'id\']==null){
$this->error(\'此账号不存在\');
}
//判断是否填邮箱
if($info[\'email\']!=$email){
$this->error(\'邮箱跟您注册的邮箱不一致\');
}
$key = md5 ( $info [\'username\'] . \'+\' . $info [\'password\'] ); // MD5不可逆,验证$string中username,防止URL更改username
$string = base64_encode ( $info [\'username\'] . \'+\' . $key ); // 加密,可解密
$time = time ();
$code=md5 ( \'mytime\'.$time );
// 生成URL
$findpwd = $_SERVER [\'HTTP_HOST\'] . U(\'Change/changePassword\' ,array(\'key\'=>$key,\'info\'=>$string,\'time\'=>$time,\'code\'=>$code)); // code是用来检验time是否有修改过
// 调用发送邮件函数
$username = $info [\'username\'];
$title="找回密码";
$content="
//发送邮件
public function send_mail($title, $content,$to, $chart = \'utf-8\', $attachment = \'\') {
//查询邮箱配置信息
$sys=M(\'sysconfig\')->where(array(\'config_name\'=>\'email\'))->field(\'config_text\')->find();
$sys=unserialize($sys[\'config_text\']);
include \'./ThinkPHP/Library/Vendor/PHPMailer/class.phpmailer.php\';
//class.smtp.php
include \'./ThinkPHP/Library/Vendor/PHPMailer/class.smtp.php\';
$mail = new PHPMailer ();
$mail->CharSet = $chart; // 设置采用gb2312中文编码
$mail->isSMTP (); // 设置采用SMTP方式发送邮件
$mail->Host = $sys[\'mail_host\']; // 设置邮件服务器的地址
$mail->SMTPSecure = \'ssl\';
$mail->CharSet = \'UTF-8\';
$mail->Port = $sys[\'smtp\']; // 设置邮件服务器的端口,默认为25
$mail->From =$sys[\'mail_from\']; // 设置发件人的邮箱地址
$mail->FromName =$sys[\'mail_fromname\']; // 设置发件人的姓名
$mail->SMTPAuth = true; // 设置SMTP是否需要密码验证,true表示需要
$mail->Username = $sys[\'mail_name\']; // 设置发送邮件的邮箱
$mail->Password = $sys[\'mail_password\']; // 设置邮箱的密码
$mail->Subject = $title; // 设置邮件的标题
$mail->AltBody = "text/html"; // optional, comment out and test
$mail->Body = $content; // 设置邮件内容
$mail->IsHTML ( true ); // 设置内容是否为html类型
$mail->WordWrap = 50; // 设置每行的字符数
// $mail->AddReplyTo ( "地址", "名字" ); // 设置回复的收件人的地址
$mail->AddAddress ( $to, "" ); // 设置收件的地址
if ($attachment != \'\') {
$mail->AddAttachment ( $attachment, $attachment );
}
if ($mail->Send ()) {
//$status1 = "$to" . \' 已投送成功
\';
$status = 1;
} else {
//$status2 = "$to" . \' 发送邮件失败
\';
$status = 0;
}
return $status;
}