findPwdAction.class.php error('帐号不能为空!'); $yzm = I('post.yzm') ? trim(I('post.yzm')) : ''; $captcha = cookie('captcha'); //验证码检测 if(!$yzm || !$captcha) $this-error('验证码不能为空!'); $captcha = authcode(coo
error('帐号不能为空!');
$yzm = I('post.yzm') ? trim(I('post.yzm')) : '';
$captcha = cookie('captcha');
//验证码检测
if(!$yzm || !$captcha) $this->error('验证码不能为空!');
$captcha = authcode(cookie('captcha'),'DECODE');
$captchaArr = explode('#',$captcha);
if(count($captchaArr) != 2 || $captchaArr[0] != $yzm) $this->error('验证码错误!');
if($captchaArr[1] < time() - 60*5) $this->error('验证码超时!');
//分辨帐号类型
$type = 0; //账号类型:0空,1手机,-1邮箱
if(preg_match('/^1[3456789]\d{9}$/',$account)) $type = 1;
if(preg_match('/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/',$account)) $type = -1;
//账号是否存在
$M = M('member');
if($type > 0){ //手机
//发送短信验证
(sendCode($account,$yzm))?$this->success('手机验证码发送成功!'):$this->error('手机验证码发送失败!');
}elseif($type < 0){ //邮箱
//发送邮箱验证
$title = "找回密码(系统邮件,请勿回复)";
$code = rand(100000,999999);
$content = "
亲爱的用户".$this->userinfo[mname].",您好:
验证码
".$code."
有效期为5分钟。如非本人操作,请忽略本邮件。
这只是一封系统自动发出的邮件,请不要直接回复。
";
if(sendMail($account,$title,$content)){
$code = authcode($code.'#'.time().'#'.$account, 'ENCODE');
cookie('captcha',null);
cookie('code',$code);
$this->success('邮箱验证码发送成功!');
}else $this->error('邮箱验证码发送失败!');
}
}
function sendCode($phone,$yzm){
$captcha = cookie('captcha');
if(!$phone) return '手机号码不能为空';
if(!preg_match('/^1[3456789]\d{9}$/',$phone)) return '手机号码格式不正确';
if(!$yzm) return '验证码不能为空';
$captcha = authcode(cookie('captcha'),'DECODE');
$captchaArr = explode('#',$captcha);
if(count($captchaArr) != 2 || $captchaArr[0] != $yzm) return '验证码错误';
if($captchaArr[1] < time() - 60*5) return '验证码超时';
$code = rand(100000,999999);
$con = file_get_contents('http://domain.com/api/GetCode.php?tel='.$phone.'&code='.$code);
if($con == '100'){
$code = authcode($code.'#'.time().'#'.$phone, 'ENCODE');
cookie('captcha',null);
cookie('code',$code);
return true;
}else return '发送失败';
}
function sendMail($to, $title, $content) {
Vendor('PHPMailer.PHPMailerAutoload');
$mail = new PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host=C('MAIL_HOST'); //smtp服务器的名称
$mail->Port = C('SMTP_PORT'); //邮件发送端口
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = C('MAIL_SMTPAUTH'); //启用smtp认证
$mail->Username = C('MAIL_USERNAME'); //发件人邮箱名
$mail->Password = C('MAIL_PASSWORD') ; //邮箱密码
$mail->From = C('MAIL_FROM'); //发件人地址
$mail->FromName = C('MAIL_FROMNAME'); //发件人姓名
$mail->AddAddress($to,"尊敬的客户");
$mail->WordWrap = 50; //设置每行字符长度
$mail->IsHTML(C('MAIL_ISHTML')); // 是否HTML格式邮件
$mail->CharSet=C('MAIL_CHARSET'); //设置邮件编码
$mail->Subject =$title; //邮件主题
$mail->Body = $content; //邮件内容
$mail->AltBody = "这是一个纯文本的身体在非营利的HTML电子邮件客户端"; //邮件正文不支持HTML的备用显示
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
// 1 = errors and messages
// $mail->ErrorInfo;
// 2 = messages only
if ($mail->send()) {
return true;
} else {
// return $mail->ErrorInfo;
return false;
}
}
