Using the PHP Function CheckDNSR to Validate Email Addresses
One of the hardest things to validate on the web is email addresses. Even if you use the most stringent regular expression for syntax validation, it's no guarantee that an email address exists or is valid. Luckily, PHP has a built in function that can do part of the work for you, allowing you to verify if an IP address or host name corresponds to a DNS record. In this article we'll take a look at the php function checkdnsrr, and how it can be used to validate email addresses before doing anything else on the server.
This is a very useful function when dealing with email address validation. It looks up a list of records that correspond to a hostname or IP address and returns a boolean value of whether or not it exists. The required parameters are the hostname or IP address and the type of record to search for. The types available are A, AAAA, CNAME, NAPTR, PTR, SOA, and SRV.
It's important to note that this is not a foolproof way of checking for a domain name, but it does help to cut down on the amount of spam sent to your servers. It's always good practice to validate an email address in multiple ways, and you should always check the syntax of an email as well, but using this function can save you some time and CPU. Just make sure to word error messages correctly, and always give the user a chance to bypass the verification check if they feel they know their email address is valid.