tags:

views:

699

answers:

9

Possible Duplicates:
Is there a php library for email address validation?
How to check if an email address exists without sending an email?

hi guys,

how can i validate the email address to email provider just like yahoo?

scenario:

[email protected]

how can i validate it to yahoo.com that the email stated above is valid?

Thanks in Advance.

---- PHP Rules ----

+4  A: 

The only "propper" way to validate an email is to actually try to send an email to that address, but most times a regular expression will do the trick.

To complicate the issue, you might just want a simple validation like this

^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$

or a somewhat more complex one like this

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b

There is a pretty good article about email validation here

Nippysaurus
the problem is not in the format of the email. The validation is from the email address if it is valid on the email provider just like yahoo.com.
ooooh. Sorry, my mistake.
Nippysaurus
It's ok... by the way thanks for the reply---- PHP Rules ----
+2  A: 

Make an SMTP connection to the server, and do a 'Sender-Verify' lookup:

telnet <Yahoo MX> 25
helo here.com
mail from: [email protected]
rcpt to: [email protected]
data

You'll either get a code to proceed with transmission, or be given an recipient invalid message.

Chaos
I think you'll find that often doesn't work because spammers would use it to verify email addresses.
cletus
Actually it's pretty common - a lot of mail servers (like Exim) - use it to validate the sender before accepting new mail. I run a large mail platform where every message is validated this way.
Chaos
If you do this, don't forget to use angle brackets around the email addresses as required by the SMTP standard: mail from:<[email protected]>
Greg Hewgill
cletus is right, most major mail providers (including yahoo, iirc) will respond to any request like this either always getting a positive result or always a negative result, whether the email exists under that domain or not. the only sure-fire way is to send a confirmation email.
EvanK
Upvoted because sender address verification is the (only!) correct answer so far it seems. However, I'd recommend trying to find a library to do the SAV, or at least to do the SMTP. Simple connections like the above will fail in many situations: you should wait for the EHLO response before starting the "MAIL FROM", many mail servers will drop the connection if you keep on submitting data; "here.com" should be the correct FQDN for your host. There's no need for 'DATA' -- if RCPT TO succeeds, the address is OK. You should cache responses to avoid thrashing servers.
jmtd
+4  A: 

I hope the following document helps:

Validate an E-Mail Address with PHP, the Right Way

Alan Haggai Alavi
Thanks for the link sir...---- PHP Rules ----
No problem. :-)
Alan Haggai Alavi
Beware of this article! Read the comments!
Julian Young
A: 

Use this free web service through either a SOAP call, GET, or POST. All you need to do is feed it an email address and it will return a boolean value representing whether or not it's an actual, deliverable email address:

http://www.webservicex.net/ValidateEmail.asmx?op=IsValidEmail

James Skidmore
Oh great, another way for unscrupulous spammers to obtain working email addresses.
Greg Hewgill
I just tested that service and it seems to work.
Chris Thompson
+1  A: 

Look up an MX record for that email address.

Here Be Wolves
A: 

There are many spam/trash mailers out there (www.spam.la), that allow you to receive mails to any address. Therefore I suggest not to rely on a "valid" email in the usual sense. Maybe OpenID is an option? For just checking for a "valid" format you can maybe make use of existing functionality like filter_var()/FILTER_VALIDATE_EMAIL.

merkuro
+1  A: 

The following regex matches email addresses:

^([\w-\.]+)@((\[[0–9]{1,3}\.[0–9]{1,3}\.[0–9]{1,3}\.)|(([\w-]+\.)+))
([a-zA-Z]{2,4}|[0–9]{1,3})(\]?)$

[email protected] - VALID

[email protected] - VALID

[email protected] - VALID

rashmi.pandit@gmail - INVALID

[email protected] - INVALID

If you want more complex as per RFC guidelines, you can use this one:

^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$
Rashmi Pandit
This will reject valid email addresses, including those with plus and underscore characters in them.
David Dorward
_ are allowed, the second pattern is as per RFC guidelines.
Rashmi Pandit
+3  A: 

You could send an email to the address and have the user verify it by clicking on a link.

PHLAK
Sometimes the obvious solution is the best one :) As discussed in other answers, any other (automated) way is likely to be immediately misused by spammers, and therefore won't work.
MaxVT
A: 

Most of the above answers look at regular expression check of email address. To actually see if the email address is valid you will need to connect to the SMTP server and send it commands. All details and PHP code is available here.

Use sparingly, Yahoo servers might block you if you send a lot of requests. Also it is highly recommended to use it along with the regular expressions as described by others.

Webber