PHP怎么实现imap收取一封有验证码的邮件,自动注册和登录得到Token

想实现一键注册成功,并且登录 http://adm.fxtcvip.com进去取到Token码为最终目的,

这里是提交参数去注册会员但是注册必须要邮箱收到验证码,填写到最后,才可以提交注册成功,以下网址最后填写邮箱打开就可以发送验证码,邮箱收到邮件取到验证才可以注册成功
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
http://adm.fxtcvip.com/send_email_register_verify_code?email=$取email
发邮件验证码

http://adm.fxtcvip.com/reg?user_name=$随机7位小写用户名&password=$随机3小写4个数字&phone=$随机11位&qq=$qq号码10位&email=$取email&remark=http://www.paypal.com, http://www.amazon.com,http://www.facebook.com&ver_code=$邮件验证码
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

我有很多这个邮箱都可以imap收信
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
inutaccay137@mail.com----390bXzrnAG
imatlonsou445@mail.com----45xLmw2zZR
imap服务器SSL : imap.mail.com    端口:993
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
邮件内容如下:就是想取验证码注册
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
发件人: 
Rola-IP<rolaproxy@gmail.com>   
收件人: 
时间: 
2021年3月20日 (周六) 20:22
大小: 
11 KB
[ROLA-IP] Your Regisiter Code is: 360669. Expire after 5 minutes
--------------------------------------
ROLA-IP
Address: San Francisco.US
Phone: (+1) 213 - 476 - 0037
Tax: (+1) 213 - 476 - 0030
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

不知道用php能实现吗??????
 

代码已经切换为你邮局的,可以正常读取邮件注册了,如果读取不到验证码,要适当延长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";

?>

看了这个了么: https://blog.csdn.net/weixin_36691991/article/details/104991983