I am currently attempting to check the validity of an email address by first checking if an MX record exists, using getmxrr() or dns_get_record() with PHP 7 on a DigitalOcean droplet.
In my example (which returns the incorrect response), I am attempting to check an email address on the domain “nuwatches.com”. Using dns_get_record(”nuwatches.com”, DNS_ALL), I’m returned an array that DOES include an MX record, even though I know this does not exist in reality:
[5] => Array (
[host] => nuwatches.com.com
[class] => IN
[ttl] => 27
[type] => MX
[pri] => 1
[target] => mail.user-mail.net
)
However, if I use nslookup directly from the console on the DigitalOcean droplet, I’m correctly told that no MX record exists.
In addition, if I run the dns_get_record() function on a different droplet, or using an online PHP code runner, I’m also given the correct answer (which is that no MX record exists).
I’ve spoken to DigitalOcean support and they suggest there’s something strange happening with PHP on that particular droplet, perhaps with caching issues, but I can’t at all figure out what might be causing the discrepancy, especially as I'm not caching anything myself.
As it stands, my only option to get the correct response on this droplet is to run nslookup and then parse the result, but I would like to use dns_get_record() if possible.
I’d appreciate any suggestions. Thanks!
I am having similar problems with
dns_get_record()when calling it with the default value for record typeDNS_ANYor when calling it withDNS_ALL.php dns_get_records( host, type ) is returning false with type=DNS_ALL but returns DNS records with DNS_TXT or DNS_A
A solution that worked for me was to use:
I am still investigating the reason behind this behaviour.