Verify Valid Domain

Use this code to verify if the domain part of an email address is valid:


use Net::DNS;

$email = "[email protected]";
(undef, $domain) = split (/@/, $email);
$resolver = new Net::DNS::Resolver();
$response ||= $resolver->query($domain, "MX")
  || $resolver->query($domain, "A");
defined ($response) ? print "$domain is valid"
  : print "$domain is invalidn";

It might also be a good idea to skip known domains, such as yahoo.com, google.com, etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.