Re: [PHP] Email checking
On Thu, 13 Sep 2001 11:28:01 -0700, you wrote: like to be able to check to see that: the email is in the correct format and the domain actually exists. Can anyone lend a hand? [putting the try it this way bit first] The only way to validate an email address is to try to send email to it. If you are doing anything where users add themselves to a mailing list, then best practice is to use a double-opt-in. (this is what you had to do when signing up to the PHP list). a) user requests that their email address is signed up b) a email with a unique subject line is sent to the address c) when the email is replied to, the account goes live This way, nobody can be added to the database maliciously, and you are guaranteed to have a working email address. However... if (!ereg(([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+), $email)) { $result = 'Not a valid email address'; } checks that an email address parses ok. list(,$domain) = split('@', $email); should put the domain component in $domain. Now, you have to check that an MX record exists for that domain. Here's a script that will give you some idea of what you will be receiving: http://www.declude.com/tools/lookup.php If you want to be really paranoid, you can then connect to the host(s) in the MX record on port 25 and check they have SMTP servers running. Even when you've done all this: 1) The user portion of the address may be incorrect (a few SMTP servers offer VRFY though). 2) The MX record may be wrong, and the SMTP server might refuse mail for that domain djo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Email checking
Have you tried: http://zend.com/codex.php?CID=11 --- Max Mouse [EMAIL PROTECTED] wrote: I've been looking to check the validity of an email address when it's entered by a person on a from. So far, I have found many different versions __ Terrorist Attacks on U.S. - How can you help? Donate cash, emergency relief information http://dailynews.yahoo.com/fc/US/Emergency_Information/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Email checking
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]