1

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:

asdfasdf@yahoo.com

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

Thanks in Advance.

---- PHP Rules ----

Community
  • 1
  • 1
user126445
  • 37
  • 3
  • 1
    I think the wording of this question is somewhat misleading. Please be clear that this is to check that the email address actually exists, not just the format of the email address. – Nippysaurus Jun 22 '09 at 04:44
  • Yes, the title should be something like "Validating authenticity of emails with providers or domains or source" – this. __curious_geek Jun 22 '09 at 04:51
  • sorry guys I didn't know what is the term for that... – user126445 Jun 22 '09 at 05:05
  • This has been asked before: http://stackoverflow.com/questions/565504/how-to-check-if-an-email-address-exists-without-sending-an-email – jmtd Jun 22 '09 at 09:42

9 Answers9

4

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
  • 20,110
  • 21
  • 77
  • 129
4

I hope the following document helps:

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

Alan Haggai Alavi
  • 72,802
  • 19
  • 102
  • 127
3

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

PHLAK
  • 22,023
  • 18
  • 49
  • 52
  • 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 Jun 22 '09 at 06:20
2

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

telnet <Yahoo MX> 25
helo here.com
mail from: here@there.com
rcpt to: asdfasdf@yahoo.com
data

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

Alex Taylor
  • 7,128
  • 2
  • 26
  • 22
  • 3
    I think you'll find that often doesn't work because spammers would use it to verify email addresses. – cletus Jun 22 '09 at 04:41
  • 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. – Alex Taylor Jun 22 '09 at 04:44
  • If you do this, don't forget to use angle brackets around the email addresses as required by the SMTP standard: mail from: – Greg Hewgill Jun 22 '09 at 04:48
  • 1
    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 Jun 22 '09 at 05:08
  • 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 Jun 22 '09 at 09:37
1

Look up an MX record for that email address.

jrharshath
  • 25,975
  • 33
  • 97
  • 127
1

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})(\]?)$

rashmipandit@gmail.com - VALID

rashmi.pandit@gmail.com - VALID

rashmi_pandit@gmail.com - VALID

rashmi.pandit@gmail - INVALID

rashmi+pandit@gmail.com - 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
  • 23,230
  • 17
  • 71
  • 111
0

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
  • 49,340
  • 32
  • 108
  • 136
0

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
  • 6,161
  • 2
  • 27
  • 29
0

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
  • 300
  • 3
  • 12