Reputation: 5256
I'm trying to validate whether an MX record exists for a given domain, and nothing works.
// 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,
));
Here's what I'm getting (for both gmail.com.
and gmail.com
, tried separately):
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
If I replace MX
with A
, dns_get_record()
returns a correct IP address, and checkdnsrr()
returns true
.
There's nothing in the logs (except for the above warning), and googling didn't help. How do I debug this?
UPD The issue appears in my local VirtualBox environment (PHP 5.6.39); everything actually works on the production server (PHP 7.3.11)
Upvotes: 0
Views: 978