E-mail Checking

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

User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

E-mail Checking

Post by tecktalkcm0391 »

Does anybody have anywhere/code that checks if an email is an actually email address so users can't type something like asdflkja0ifdjalkfjaigj@jlkajdflafdjlak.com and then my website execpts it.

Or if someone could point me in the right direction it would be great!

Thanks!
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

This is a tired discussion. Google for "preg_match e-mail address" or "regex e-mail address" or search this forum.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

That's it as a JS literal:

Code: Select all

/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}/i
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

I want to do something like this:
http://www.mailtester.com/test.php?emai ... sdjalf.com

but it would just return valid or not valid.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Why not just check that it is formed like an email address with regex? Is it absolutely VITAL that the email is a REAL email address... cuz there is no way to know that for sure. (that I know of)
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Not absolutely vital but vital enought. :wink: :wink: :wink: Did you check out that website? It works for every email i entered which was about 10. :)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Why not just check that it is formed like an email address with regex? Is it absolutely VITAL that the email is a REAL email address... cuz there is no way to know that for sure. (that I know of)
Yeah. I'm not sure how that mailtester site works but I bet it is flawed. Regex is generally the best you can do with any reliability as far as I know.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

The Ninja Space Goat wrote:Why not just check that it is formed like an email address with regex? Is it absolutely VITAL that the email is a REAL email address... cuz there is no way to know that for sure. (that I know of)
Well you could send it a token and wait for the response.

I've got a tool here that connects to the remote server to see if it will accept mail for a particular address but even this doesn't prove the address is good... only that the mail server will accept mail for it.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

OK, well could you send me the codes for it cause that would be awsome!
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

nice... you built that? That's pretty cool.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Yeah he did. I get your point now that I played around with it. Still, How did you do that ?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

bokehman wrote:I've got a tool here that connects to the remote server to see if it will accept mail for a particular address but even this doesn't prove the address is good... only that the mail server will accept mail for it.
That is freaking sweet! Have you ever opened that code or published it? Me thinks it would be a nice fit in the PHPClasses.org library.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

ole wrote:
Why not just check that it is formed like an email address with regex? Is it absolutely VITAL that the email is a REAL email address... cuz there is no way to know that for sure. (that I know of)
Yeah. I'm not sure how that mailtester site works but I bet it is flawed. Regex is generally the best you can do with any reliability as far as I know.
It will be flawed. I can only see a few ways to do it.

1. Send an email and ask for a reply
2. Hope the server informs you if the RCPT envelope doesn't exist before DATA is sent
3. Hope the server accepts VRFY as a command

The latter two are almost certainly not going to work these days. Number 1 is the generally accepted way to do it.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

If you want to use RegEx, have a look at RegExpLib.com's Email Expressions.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

d11wtq wrote:1. Send an email and ask for a reply
I am so bad at forgetting to think about the MOST OBVIOUS solution there is. Wow. Thanks for the smack in the head man. Geeze!
Post Reply