代码已经切换为你邮局的,可以正常读取邮件注册了,如果读取不到验证码,要适当延长sleep的等待时间,现在是15秒后再读取邮件

<meta charset="utf-8"/>
<?php
set_time_limit(100);
//date_default_timezone_set('PRC');
function matchMailHead($str){
$headList = array();
$headArr = array('subject','date');
foreach ($headArr as $key){
if(preg_match('/^'.$key.':(.*?)[\n\r]$/ism', $str,$m)){
$match = trim($m[1]);
$headList[$key] = $key=='date'?strtotime($match): mb_decode_mimeheader($match);
}
}
return $headList;
}
function getValidCode($mailserver,$email,$password){
if(strpos($mailserver,":993")!==false){//ssl
$host= "{".$mailserver."/imap/ssl/novalidate-cert}INBOX";
}
else{
$host= "{".$mailserver."}INBOX";
//$host= "{".$mailserver."/notls}";
}
//echo $host;
$mbox = imap_open($host, "$email", "$password") or die("can't connect: " . imap_last_error());
$sorted = imap_sort($mbox, SORTDATE, 1);//日期降序排列
$total=count($sorted);
$num=5;//读取最新的前5封邮件找验证码,如果你这个邮箱收发量大,这里改下数字,如改为10,读取前10封
if($num>$total)$num=$total;
for ($i=0;$i<$num;$i++){
$no=$sorted[$i];
$headers = imap_fetchheader($mbox, $no); //获取信件标头
$headArr = matchMailHead($headers); //匹配信件标头
//echo json_encode($headArr)."<HR>";
if($headArr["subject"]=='Welcome to Rola-IP platform'){//验证码邮件标题匹配读取验证码
$body= base64_decode(imap_fetchbody($mbox, $no, 1));
preg_match("/Your Regisiter Code is:\s*(\d+)/i",$body,$m);
return $m[1];
}
}
imap_close($mbox);
return '';
}
function get_user_name($num){
$un="";
for($i=0;$i<$num;$i++)$un.=chr(rand(1,26)+96);
return $un;
}
function get_password($chrnum,$num){
$pwd="";
for($i=0;$i<$chrnum;$i++)$pwd.=chr(rand(1,26)+96);
for($i=0;$i<$num;$i++)$pwd.=rand(0,9);
return $pwd;
}
function get_num($num,$isQQ){
$v=$isQQ?rand(1,9):1;
$num-=1;
for($i=0;$i<$num;$i++)$v.=rand(0,9);
return $v;
}
function sendCode($email){
$content=file_get_contents("http://adm.fxtcvip.com/send_email_register_verify_code?email=$email");
$o=json_decode($content);
if($o->code!==0)die("发送验证码失败==》".$o->msg);
}
/////////////////////////////////////////////////////////////////////////
$email=$_GET["email"];
$password=$_GET["password"];
$mailserver=isset($_GET["mailserver"])?$_GET["mailserver"]:"imap.mail.com:143";///////////传递了服务器地址使用传递的
sendCode($email);//发送验证码
sleep(15);//暂停15秒等待对方服务器发邮件
$ver_code=getValidCode($mailserver,$email,$password);
if($ver_code=="")die("获取验证码失败,请适当调整sleep时间给对方服务器发送邮件~~");
$user_name=get_user_name(7);
$pwd=get_password(3,4);
$phone=get_num(11,false);
$qq=get_num(10,true);
$url="http://adm.fxtcvip.com/reg?user_name=$user_name&password=$pwd&phone=$phone&qq=$qq&email=$email&remark=http://www.paypal.com,http://www.amazon.com&ver_code=$ver_code";
$content=file_get_contents($url);//注册
$o=json_decode($content);
if($o->code!==0)die("注册失败===>".$o->msg.$url);
//注册成功登陆系统获取token
$url="http://adm.fxtcvip.com/login?user_name=$user_name&password=$pwd";
$content=file_get_contents($url);//登陆系统获取token
$o=json_decode($content);
if($o->code!==0)die("登陆系统失败===>".$o->msg);
echo "Token:".$o->data->token."<br>user_name:$user_name<br>password:$pwd";
?>