gpt4 book ai didi

php - fsockopen() : unable to connect not work with PHP (Connection timed out)

转载 作者:可可西里 更新时间:2023-11-01 12:59:35 26 4
gpt4 key购买 nike

我有这个代码:

$domain = 'massag.com';

$hosts = array();
$mxweights = array();
getmxrr($domain, $hosts, $mxweights);

var_dump($hosts);
var_dump($mxweights);

$host = gethostbynamel($hosts[0])[0];
var_dump($host);

$f = @fsockopen($host, 25, $errno, $errstr, 10);

if(!$f) {
var_dump('NOT CONNECTED');
}

它没有连接到smtp服务器但是当我使用命令时

smtp:217.196.209.9

关于 mxtoolbox.com它已连接。

我的 PHP 代码有问题吗?我已经尝试将 $host 替换为 smtp.massag.com 但没有帮助。

最佳答案

使用 dig 查询提供的 IP 或其反向 DNS,它显示没有 MX 记录,因此预计会出现错误。

dig -x 217.196.209.9 MX | grep 'IN.*MX'
;9.209.196.217.in-addr.arpa. IN MX

dig smtp.miramo.cz MX | grep 'IN.*MX'
;smtp.miramo.cz. IN MX

但在 massag.com 上返回结果

dig massag.com MX | grep 'IN.*MX'
;massag.com. IN MX
massag.com. 85375 IN MX 20 miramo3.miramo.cz.
massag.com. 85375 IN MX 10 smtp.miramo.cz.

最后,添加一些测试以避免不必要的错误并使用工作域

<?php
$domain = 'massag.com';

if(getmxrr($domain, $hosts, $mxweights)){
print_r($hosts);
print_r($mxweights);
if(count($hosts) > 0){
$host = gethostbynamel($hosts[0])[0];
print("Found host: " . $host . "\n");

$f = fsockopen($host, 25, $errno, $errstr, 10);

if(!$f){
var_dump('NOT CONNECTED');
}
}else{
print("no MX record found\n");
}
}
?>

使用 tutorialspoint.com 作为域的结果:

    Array
(
[0] => ALT2.ASPMX.L.GOOGLE.com
[1] => ASPMX.L.GOOGLE.com
[2] => ALT1.ASPMX.L.GOOGLE.com
[3] => ALT4.ASPMX.L.GOOGLE.com
[4] => ALT3.ASPMX.L.GOOGLE.com
)
Array
(
[0] => 5
[1] => 1
[2] => 5
[3] => 10
[4] => 10
)
Found host: 74.125.128.26

使用 OP (massag.com) 提供的域名

    Array
(
[0] => smtp.miramo.cz
[1] => miramo3.miramo.cz
)
Array
(
[0] => 10
[1] => 20
)
Found host: 217.196.209.9

关于php - fsockopen() : unable to connect not work with PHP (Connection timed out),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51465654/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com