0

Up until Facebook closed it's doors on 'Public Post Search' I used to run a site that allowed for this function. Right now am building a new site and have a landing page that allows for the visitor (old or new) to sign up to be notified when the new site is up and running. This is done via email. Unfortunately I have suffered some people inputting non email addresses so solved that with a PHP function, however more recently I've started suffering from what are clearly not valid email addresses like 'foo@bar.com' etc...

Is there a recommended PHP function to check whether the email address is fully valid? If not, is there a free service which has an API that I could use to check whether the address is valid?

Alireza Sabahi
  • 647
  • 1
  • 12
  • 35
GeordieDave1980
  • 589
  • 4
  • 11
  • 25
  • 5
    How is `foo@bar.com` "clearly not valid"? It looks perfectly valid to me. – Red Alert Aug 25 '15 at 23:31
  • "valid" is a relative state. maybe for you, "valid e-mail" means a e-mail where the inbox is read by a human ? for this you need to use a validation step where the reader of the mail will clic on a link in the e-mail to validate the fact that he can read it – mmm Aug 25 '15 at 23:36
  • More info about "valid" email addresses: http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/ – Mike D. Aug 25 '15 at 23:38
  • Basically I had someone enter 1234 and that was it, I won't divulge of course what the @ domain name was etc but that was just one that was entered, another was fgsfgsfgsfgs and a third being f***you at the beginning. These are the types of idiots I don't want loading my database of signups with false email addresses. – GeordieDave1980 Aug 25 '15 at 23:46
  • foo does not want your email tests: http://bar.com/ –  Aug 25 '15 at 23:46
  • 1
    who says 1234 @ any domain is not a valid address?? –  Aug 25 '15 at 23:47
  • All I'm asking, is that if there is a free validation service that also supplies an API, can you suggest one? – GeordieDave1980 Aug 25 '15 at 23:53

1 Answers1

5

The only reliable way to know if an email address is valid is to attempt to send an email to that address and check for a hard or soft bounce.

You can validate that the format of the email address satisfies format checks and therefore could be valid. foo@bar.com would pass that check.

In the ancient days of the internet (the 90's), many SMTP servers would allow one to query "is this email address valid" without going through with sending an email. That was abused by spammers to validate spam lists, so pretty much every SMTP server has that part of the protocol disabled.

Eric J.
  • 147,927
  • 63
  • 340
  • 553