require"include/class.phpmailer.php";
require"include/class.smtp.php";
session_start();
$pe= trim($_POST['pe']);
$num=rand(0,9).rand(0,9).rand(0,9).rand(0,9);
if(preg_match("/^(13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/",$pe)){
$sendUrl = 'http://v.juhe.cn/sms/send'; //短信接口的URL
$sendAppkey = 'b71ad52ddf5a564edfb829b2140af9e0';
$sendtpl_id = '21992';
$c_mobile=$pe; //手机号码
$smsConf = array(
'key' => $sendAppkey, //您申请的APPKEY
'mobile' => $c_mobile, //接受短信的用户手机号码
'tpl_id' => $sendtpl_id, //您申请的短信模板ID,根据实际情况修改
'tpl_value' =>'#code#='.$num //验证码
);
$content = juhecurl($sendUrl,$smsConf,1); //请求发送短信
if($content){
$result = json_decode($content,true);
$error_code = $result['error_code'];
if($error_code == 0){
$_SESSION['yzm']=$pe."-".$num;
echo 1;
//状态为0,说明短信发送成功
//echo "短信发送成功,短信ID:".$result['result']['sid'];
}else{
//状态非0,说明失败
$msg = $result['reason'];
echo $msg;
}
}else{
//返回内容异常,以下可根据业务逻辑自行修改
echo 2;
}
}else{
$user_email = "171397782@qq.com";
$_SESSION['yzm']=$pe."-".$num;
$to=$pe;
$title = "取回密码邮件";
$content = "尊敬的先生/女士:
验证码".$num."为此邮件为系统邮件,请勿直接回复";
sendMail($user_email,$to,$title,$content);
echo 1;
}
function sendMail($from,$to,$title,$content){
date_default_timezone_set('PRC');
ignore_user_abort();
set_time_limit(0);
$interval = 60*1;
$row = explode('@',$from);
$Username = $row[0];
$mail = new PHPMailer();
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->SMTPAuth=true;
$mail->Host = 'smtp.qq.com';// 网易 smtp.163.com // QQ smtp.qq.com
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->Hostname = 'http://web.winit168.cn/';
$mail->CharSet = 'UTF-8';
$mail->FromName = '导游';
$mail->Username =$Username;
$mail->Password = 'ezejyfwzefcybggf';//授权码
$mail->From = $from;
$mail->isHTML(true);
$mail->addAddress($to,'to');
$mail->Subject = $title;
$mail->Body = $content;
$status = $mail->send();
}
function juhecurl($url,$params=false,$ispost=0){
$httpInfo = array();
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22' );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 30 );
curl_setopt( $ch, CURLOPT_TIMEOUT , 30);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
if( $ispost )
{
curl_setopt( $ch , CURLOPT_POST , true );
curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
curl_setopt( $ch , CURLOPT_URL , $url );
}
else
{
if($params){
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
}else{
curl_setopt( $ch , CURLOPT_URL , $url);
}
}
$response = curl_exec( $ch );
if ($response === FALSE) {
//echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
curl_close( $ch );
return $response;
}
?>
一键复制
编辑
Web IDE
原始数据
按行查看
历史