dns_get_mx、dns_get_record和检查不适用于 MX

我正在尝试验证给定域是否存在 MX 记录,但没有任何效果。


// prepare the hostname

$hostname = 'gmail.com';

$hostname = idn_to_ascii($hostname);//php.net/manual/function.checkdnsrr.php#113537

$hostname = sprintf('%s.', $hostname);//php.net/manual/function.checkdnsrr.php#119969

// perform the checks

dns_get_mx($hostname, $dns_get_mx); // a.k.a. getmxrr()

$dns_get_record = dns_get_record($hostname, DNS_MX);

$checkdnsrr = checkdnsrr($hostname, 'MX');

// output the result

var_dump(array(

    'hostname' => $hostname,

    'dns_get_mx' => $dns_get_mx,

    'dns_get_record' => $dns_get_record,

    'checkdnsrr' => $checkdnsrr,

));

以下是我得到的内容(对于 gmail.com 和 分别尝试):gmail.com


Warning: dns_get_record(): A temporary server error occurred. in /var/www/html/example.php

array (size=4)

  'hostname' => string 'gmail.com.' (length=10)

  'dns_get_mx' => 

    array (size=0)

      empty

  'dns_get_record' => boolean false

  'checkdnsrr' => boolean false

如果我用 替换,dns_get_record() 返回一个正确的 IP 地址,而检查数r() 返回 。MXAtrue


日志中没有任何内容(除了上面的警告),谷歌搜索也无济于事。如何对此进行调试?


断续器此问题出现在我的本地虚拟盒环境(PHP 5.6.39)中;一切实际上都在生产服务器上工作(PHP 7.3.11)


郎朗坤
浏览 188回答 1
1回答

慕容森

虚拟框似乎正在覆盖 ,这搞砸了来宾计算机上的DNS。/etc/resolv.conf我现在的解决方法是:echo "nameserver 1.1.1.1" > /etc/resolv.conf更多信息
打开App,查看更多内容
随时随地看视频慕课网APP