So, if no type is provided, the function will search MX records for the given host.In our case, we need to look for MX records according to the host provided within the email address.In this article, we’ll develop a reusable step-by-step solution to validate a user’s email address as accurately as possible, in an attempt to save some work the next time an application needs to check for email validity.
It will look for the Mail Exchange record in the DNS (remember that the default type is MX), and return true if a MX record is found, which shows that the address displays a valid email domain.
If the function returns false, the email domain is not valid.
Certainly, this should sound very familiar to most Web developers, whether they are setting up their first consciously-coded script or implementing full-blown applications required to handle more complex processes.
Whatever the case, validating a visitor’s email address to see if it belongs to a real domain is always a good step to help you avoid, at least partially, several possible problems that arise when applications are receiving incoming bogus data.
In order to check whether a user’s email address actually corresponds to a real domain, we should search for the proper domain records in the DNS.
By doing so, we’re making sure that the supplied email address belongs to an existing domain.
From cluttering up databases with invalid information, to sending newsletters or similar content to email addresses at nonexistent domains, headaches are surely going to come up from receiving fake email.
Several approaches can be taken to address the problem, depending on the level of complexity desired for the validation itself.
It would be useful to have a version that works on Windows for those developers building applications to be executed on Windows servers. Most of these involve writing a custom version of the checkdnsrr() function.