Verifying Emails - the reliable way

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Verifying Emails - the reliable way

Post by patrikG »

If you need to be absolutely sure that an email is correct and working - I've just come across this script:

http://www.weberdev.com/get_example.php3/1238

It does the following:

/* This function takes in an email address (say 'shane@tuna.org')
* and tests to see if it's a valid email address.
*
* An array with the results is passed back to the caller.
*
* Possible result codes for the array items are:
*
* Item 0: [true|false] true for valid email address
* false for NON-valid email address
*
* Item 1: [SMTP Code] if a valid MX mail server found, then
* fill this array in with failed SMTP
* reply codes
*
* Item 2: [true|false] true for valid mail server found for
* host/domain
* false if no valid mail server found
*
* Item 3: [MX server] if a valid MX host was found and
* connected to then fill in this item
* with the MX server hostname
*
* EXAMPLE code for use is at the very end of this function.
*/

Neat.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I used one of those, and I did enjoy the results.

There was a significantly reduced ammount of fake emails being registered on a client's site.

I highly recommend such a system.
markbeadle
Forum Commoner
Posts: 29
Joined: Tue Dec 02, 2003 2:50 am
Location: Aachen, Germany

Post by markbeadle »

Need to be careful.

I could not get all addresses recognised (e.g. xyz@yahoo.com).

Regards
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Perhaps the best verification is the user writing from that address ;)
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

Weirdan wrote:Perhaps the best verification is the user writing from that address ;)
that's why i'm not gong to run out and get that. i have one that checks all top levels (thank you genik for a link that has all the 3+ letter top levels) and uses \w\w to check two letter country codes for the final bit, and then checks format for the rest (i'll drop in the preg call if anyone wants) and then the user has to return to the site via a link to sign up. thus validating the email.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Here's the regex writting in perl (conform with rfc822) http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
Post Reply