Re: Email checking

From: Date: Thu, 13 Sep 2001 18:38:24 +0000
Subject: Re: Email checking
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-67257@lists.php.net to get a copy of this message
So sprach »Max Mouse« am 2001-09-13 um 11:28:01 -0700 : > the domain actually exists. Can anyone lend a hand? My try: function CheckEmail($adr){ // Parameter: // $adr -> Email Adress // Rückgabewerte: // TRUE -> everything fine // Else, returns array: // Array(code, part) // Code s.u.; part: Part which caused error // -1 -> no @ in adr // -2 -> More than 1 @ (alas theoretically correct...) // -3 -> Error in Local-Part // -4 -> Error in Domainname // -5 -> Domain not existent // -6 -> No MX for Domain // Regexpe $re = array( // - Local-Part 'lp' => '[a-z_\d][-_.a-z\d]{0,}', // - Domain 'dom' => '(?:[a-z\d]{1,}(?:[-a-z\d]{0,}?){0,}?\.){0,}[a-z]{2,3}\.{0,1}' ); foreach ($re as $typ => $wert){ $re[$typ] = '÷^' . $wert . '$÷i'; } if (('' == $adr) || (FALSE === ($parts = split('@', $adr))) ){ // Nothing to do return array('code' => -1, 'part' => $adr); } if (2 > ($part_anzahl = count($parts))){ // Less than 1 @ (also 0) return array('code' => -2, 'part' => $adr); } if (2 < $part_anzahl){ // Too many @'s! return array('code' => -3, 'part' => $adr); } if (! preg_match($re['lp'], $parts[0])){ // Local-Part error! return array('code' => -4, 'part' => $parts[0]); } if (! preg_match($re['dom'], $parts[1])){ // Domain looks bogus! return array('code' => -5, 'part' => $parts[1]); } if (! checkdnsrr($parts[1], 'ANY')){ // Domain not existant return array('code' => -6, 'part' => $parts[1]); } if (! checkdnsrr($parts[1], 'MX')){ // No MX for domain return array('code' => -7, 'part' => $parts[1]); } // When we get here, everything is fine! return TRUE; } Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.digitalprojects.com | http://www.iso-top.de iso-top.de - Die günstige Art an Linux Distributionen zu kommen Uptime: 12 hours 58 minutes

« previous php.general (#67257) next »