Tag Archives: smtp

check email 存不存在

if ($_SERVER[argc]<2) {
  printf("Usage : %s filename\n",$_SERVER['argv'][0]);
  exit;
}

$filename=strftime("%H%M.txt");
$out=fopen($filename,"a");

$counter=0;
$fp=fopen($_SERVER['argv'][1],"r");
while ($data=fgets($fp,2000)) {
  $data=str_replace("\r","",$data);
  $data=str_replace("\n","",$data);
  if (checkmail($data)==TRUE) {
    printf("%s : %s \tGOOD_EMAIL!\n",$counter,$data);
    fputs($out,$data."\n");
  } else printf("%s : %s \tBAD_EMAIL!\n",$counter,$data);
  $counter++;
}
fclose($fp);
fclose($out);
exit;

// -------

function checkmail($mail){
  $host = explode('@',$mail);
  list($account,$host) = $host;

  if (!getmxrr($host,$mxa)) $mxa = array($host);
  while (list ($key, $mx) = each($mxa)) {
    if ($mxg = @fsockopen ($mx,25,$ir,$sr,5)) {
      $out = fgets($mxg, 1024);
      if (substr($out,0,3) == "220") {
        fputs ($mxg, "HELO example.com\r\n");

        $out = fgets ( $mxg, 1024 );
        fputs ($mxg, "MAIL FROM: <{$mail}>\r\n");
        $from = fgets ( $mxg, 1024 );
        fputs ($mxg, "RCPT TO: <{$mail}>\r\n");
        $to = fgets ($mxg, 1024);
        fputs ($mxg, "QUIT\r\n");
        fclose($mxg);
        if (ereg ("^250", $from) && ereg ( "^250", $to )) return TRUE;
        return FALSE;
      }
      return FALSE;
    }
    return FALSE;
  }
  return FALSE;
}