首页 > 解决方案 > fsockopen 超时取决于我的位置

问题描述

我在 PHP 上编写脚本,并且有一个问题,我有一个功能来检查一个人的电子邮件是否存在,这在我家工作正常,但不构成我的工作。

我的PHP代码:

function validate_email($email) {
  if(!preg_match ("/^[\w\.-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]+$/", $email)){
    print("false not a mail with valid format");
    return(false);
  }
  $lines = array();
  list($prefix, $domain) = explode("@",$email);
  if(getmxrr($domain,$mx,$weight) == 0) {
    file_put_contents("result.txt", "\nemail not found : " . $domain . " no MX record", FILE_APPEND);
    print("false, no mxrecord");
    return(false);
  }
  if(isset($mx[0])) {
        $connect = @fsockopen($mx[0] , 25, $errno, $errstr, 10);
    if(!$connect) {
      echo "ERROR: " . $mx[0] . " - " . $errstr . " - Code " . $errno . "\n";
      file_put_contents("result.txt", "\nemail not found : " . "ERROR : " . $mx[0] . " - " . $errstr . " - Code " . $errno, FILE_APPEND);
      return (false);
    }
    else {
      echo "\nSUCCESS: ok";
      $lines[] = fgets ($connect, 1024);
            fputs ($connect , "HELO ".$mx[0]."\r\n");
      sleep (2);
            $lines[] = fgets ($connect, 1024);
            fputs ($connect , "MAIL FROM: <mailvalidate@mailtest.com>\r\n");
      sleep (2);
            $lines[] = fgets ($connect, 1024);
            fputs ($connect , "RCPT TO: <".$email.">\r\n");
      sleep (2);
            $lines[] = fgets ($connect, 1024);
            fputs ($connect , "QUIT");
      sleep (2);
            fclose($connect);
      if (count($lines) == 4){
        list($returnStatus, $message) = explode(' ', $lines[3]);
        if($returnStatus == '250') {
          print("valid : " . $email);
          file_put_contents("result.txt", "\nEmail : " . $email , FILE_APPEND);
          return(true);
        }
      }
    }
  }
  file_put_contents("result.txt", "\nemail not found : " . $email , FILE_APPEND);
  print("\nemail not found : " . $email);
  return(false);
}  

这给了我一个错误:'连接超时 - 代码 110' 错误在这一行: $connect = @fsockopen($mx[0] , 587, $errno, $errstr, 10);

我尝试将端口更改为 587,但仍然无法正常工作。我确实运行了一个跟踪路由,它跳了 15 次,然后没有响应。无论域名如何,它都会犯同样的错误,所以我认为我的工作连接有问题。

我怀疑我工作的防火墙正在阻止数据,但现在因为无法访问它,我正在尝试其他解决方案。

抱歉英语不好,谢谢阅读:)

标签: phpemailsmtpfsockopen

解决方案


推荐阅读