我有一个PHP脚本,它使用 get_dns_record 来检索和显示通过表单提交的域的特定DNS记录。
它工作得很好,除了处理MX记录的部分有点不可靠。有时根本没有显示MX记录(在我知道的域上)。如果刷新2-3次,有时它们会出现。有时他们不会。
思想?
function getDNSRecord($domain1) {
$dns = dns_get_record( $domain1, DNS_ANY );
echo "These are DNS records";
foreach( $dns as $d ) {
// Only print A and MX records
if( $d['type'] != "A" and $d['type'] != "MX" )
continue;
// Print type specific fields
switch( $d['type'] ) {
case 'A':
// Display annoying message
echo "<b>\n" . $d['ip'] . "</b>\n is the Primary A Record for this domain.";
break;
case 'MX':
// Resolve IP address of the mail server
$mx = dns_get_record( $d['target'], DNS_A );
foreach( $mx as $server ) {
echo "This MX record for " . $d['host'] . " points to the server <b>\n" . $d['target'] . "</b>\n whose IP address is <b>\n" . $server['ip'] . "</b>. It has a priority of <b>\n" . $d['pri'] . "</b>\n.";
}
if ( $d['target'] == $domain1 ) {
echo "<div id='mx-status'>There is an issue with this MX Record</div>\n";
} else {
echo "<div id='mx-status'>This MX Record looks fine.</div>\n";
}
break;
}
}
}
答案 0 :(得分:2)
您是否考虑过使用getmxrr()
获取域名的mx记录?这里的文档:http://us2.php.net/manual/en/function.getmxrr.php