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!
You can try to use a 3rd party PHP library for that. I've just tested it and it worked for me.
bluelibraries/dns
sample
result