php - 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 次,然后没有响应。无论域名如何,它都会犯同样的错误,所以我认为我的工作连接有问题。
我怀疑我工作的防火墙正在阻止数据,但现在因为无法访问它,我正在尝试其他解决方案。
抱歉英语不好,谢谢阅读:)
解决方案
推荐阅读
- vue.js - 具有自定义名称的 Vuex 动作、vuex 模块和 mapActions
- bazel - 在 Beaglebone Black 上编译 Bazel
- browser - 如何使用机器人框架从浏览器的通知提示中选择一个选项
- python - Python 使用哪种算法进行乘法运算?
- mysql - EasyPHP-Devserver 17:无法更改 MYSQL 数据目录?
- wso2 - 如何在 WSO2 Api Manager 中禁用主机名验证?
- javascript - 在用户仅在 200px 和 300px 之间滚动时添加一个类
- php - codeigniter 3中的路由冲突
- bash - 当文件夹中有新文件时向 Slack 发送消息
- python - 在python中过滤日期列表