-5

Possible Duplicate:
PHP email validation function

How to check whether a email is valid or not in PHP?

Community
  • 1
  • 1
rsvijay
  • 70
  • 8
  • 1
    Read the FAQ and search next time. This has been answered hundreds of times already. – Brad Feb 11 '12 at 16:36

2 Answers2

0

You can only really check if an email address is valid by actually sending an email to it and checking for the return code from the SMTP server.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • How to check return code from the SMTP server. – rsvijay Feb 11 '12 at 16:43
  • By not using `mail()` but one of the many send-mail-via-smtp classes available on the net. PEAR probably has a nice one. – ThiefMaster Feb 11 '12 at 16:43
  • Okay ThiefMaster thanks for your suggestion. – rsvijay Feb 11 '12 at 16:45
  • @Downvoter: Please explain. You might have a huuuuuge regex to validate the syntax of an entered email address, but you cannot know if the address actually exists. With a properly configured smtp however, it will reject your attempt to send the email if the address is invalid. – ThiefMaster Feb 11 '12 at 16:45
  • 1
    While I'm not the downvoter, I expect it's because the SMTP code is going to be useless. Most modern SMTP servers will initially accept mail and later send a bounce to prevent spammers from easily fishing for valid accounts. Sending an email and having the user take an action specified in the mail is pretty much the only effective way to determine if the mail is *valid*. That is, you can have a well-formed email address that's totally bogus. – Charles Feb 11 '12 at 16:53
  • thank u, I wanna to check whether email adders is exits or not, not a validation. – rsvijay Feb 11 '12 at 16:54
  • @Charles: I don't think so. What you mean might be graylisting where the first email is rejected with a *temporary* error code. If you get a *permanent* error code, you know the address is invalid. Sending bounces is actually a very bad thing as it often results in backscatter spam. – ThiefMaster Feb 11 '12 at 17:21
0

GO to http://en.wikipedia.org/wiki/Email_address#Syntax

I use a PHP function on my site that checks for all those parameters.

Marc Brown
  • 601
  • 2
  • 11
  • 26