Re: QuickForm - E-Mail validation with checkdnsrr() - subdomains

From: Date: Wed, 10 Feb 2010 20:11:29 +0000
Subject: Re: QuickForm - E-Mail validation with checkdnsrr() - subdomains
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-30273@lists.php.net to get a copy of this message
Hi Markus, Which operating system are you running your PHP code from? According to http://php.net/manual/en/function.checkdnsrr.php, the function might not exist if you're using Windows. I do not have any specific experience with the checkEmail() or checkdnsrr() functions, but I have successfully used PEAR's NET_DNS package ( http://pear.php.net/package/Net_DNS) for querying DNS records on both windows and linux servers. Regards, James Collins On 11 February 2010 00:47, Markus Ernst <derernst@gmx.ch> wrote: > Hello > > This is actually not specifically a QuickForm question, but it is related > to this function I took from the QuickForm manual, and which is actually > built-in natively in QuickForm, too: > > function checkEmail($email, $domainCheck = false) > { > if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'. > '\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) { > if ($domainCheck && function_exists('checkdnsrr')) { > list (, $domain) = explode('@', $email); > if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) { > return true; > } > return false; > } > return true; > } > return false; > } > > Now it happend that the check for an e-mail address of the following form > returned false, although the address was claimed to be correct: > > firstname.lastname@subdomain.maindomain.tld > > So, both MX and A checks for subdomain.maindomain.tld returned false. > Performing the checks for maindomain.tld only, both returned true. So I > added a fix: > > function checkEmail($email, $domainCheck = false) > { > if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'. > '\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) { > if ($domainCheck && function_exists('checkdnsrr')) { > list (, $domain) = explode('@', $email); > if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) { > return true; > } > // Fix: check with removed sub domains > $spl = explode(".", $domain); > $c = count($spl); > $domain = $spl[$c - 2] . "." . $spl[$c - 1]; > if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) { > return true; > } > return false; > } > return true; > } > return false; > } > > Now, I am not familiar with anything about MX and A records. Is this a > sensible fix, which should even make it into QuickForm(2)? Or is it rather > likely to introduce new problems I am not aware of? Thanks for your > comments. > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.pear.general (#30273) next »