Email Validation For Web Forms

By | February 17, 2021

Web response form with email validation looks more professional and help to protect from posting garbage entered in email email text field. Email validation is a hard problem and cannot guarantee 100% address authenticity. There is TCP Finger protocol, which can retrieve user information via email address and confirm that the email address is valid and belongs to someone. Default finger protocol port is 79 and to validate email it is enough to send simple text query to mail server, an example: finger username@mailserver.com. But because finger protocol also opens way to get personal or company information for bad guys as well its usage was discontinued by almost all of Internet providers.
There is my web contact form from wordchaos.com site. The form has 3 text boxes: email of sender, multi-line box for text message and box for captcha verification. The code was written in PHP and is available here.
The form itself looks like:
wordchaos contact form
The most site validate email address only by checking the presence of @ symbol, some of them making awkward regex validation of whole email string.
I decided to do it is simple way: split address using @ separator and check MX (Mail Exchange) record on DNS server, the function is below, assuming that leading and trailing spaces in address string have been truncated:


function checkEmail($email)
{
   list($username,$domain)=split(‘@’,$email);
   if(!checkdnsrr($domain,’MX’) && !empty($username))
   {
      return false;
   }
   return true;
}


Leave a Reply

Your email address will not be published. Required fields are marked *