Jump to content

Command line app to verify whether an email-id exists or not


Cupidvogel

Recommended Posts

By valid I mean that the email address looks like an email address, i.e it is not something like abra..gamil.com, whereas by exists I mean that it actually exists, i.e there is indeed an email address by that name (and of course that means it is valid!). For example, kaustav153@gmail.com is a valid email address (it's my email id!), whereas kaustav_the_hottest_guy_in_the_world@gmail.com doesn't exist (hopefully!). I need it in order to verify a form credentials, it should check whether the email id the user entered exists or not so that it doesn't send notification emails to a non-existent email address. How to do it in PHP? Of course I don't want to ping the email-address with a dummy email to verify its existence!

Link to comment
Share on other sites

Regular expressions are basically the way to go, but unless you want a (theoretically) perfect expression you'll have to settle for some false positives and/or false negatives. Google can help you get one of those.

Next is checking the domain name. getmxrr can look up the mail server for a domain, but if there isn't one you should assume that the hostname also acts as a mail server (IIRC that's part of the standard). You could go another step and try a connection to the server if you wanted.

 

After that you might be able to verify a "username" but it depends on whether the mail server is nice enough to help with that. Generally you don't have to go this far: services that use an address in, for example, a registration process send an email to confirm it. This is what you should do.

Link to comment
Share on other sites

filter_var($email, FILTER_VALIDATE_EMAIL);

filter_var

 

How good this is, I'm not totally sure. I know there are some regex floating around, some take into consideration that some top level domains are more than 2 or 3 letters, but others do not. What FILTER_VALIDATE_EMAIL does exactly to check the email, I don't really know.

 

Oh, and as suggested above, send the user a confirmation e-mail they have to press a link in to really verify it's their e-mail address and it exists.

Link to comment
Share on other sites

There is this page http://verify-email.org/ where you type an email-id, and click the button to check whether the id exists or not. Problem is that the email-id doesn't get appended to the URL for the page, or then I could use a web-scraper such as BeautifulSoup (Python) to capture the response. Any other way to capture the response in PHP?

Link to comment
Share on other sites

There is this page http://verify-email.org/ where you type an email-id, and click the button to check whether the id exists or not. Problem is that the email-id doesn't get appended to the URL for the page, or then I could use a web-scraper such as BeautifulSoup (Python) to capture the response. Any other way to capture the response in PHP?

You could use curl I think.

Link to comment
Share on other sites

What FILTER_VALIDATE_EMAIL does exactly to check the email, I don't really know.

It uses a regular expression:

"/^(?!(??:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(??:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(??:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(??:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(??:(?!.*[^.]{64,})(??:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\\.){1,126}){1,}(??:[a-z][a-z0-9]*)|(??:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\\[(??:IPv6:(??:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(??!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?:?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(??:IPv6:(??:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}|(??!(?:.*[a-f0-9]{5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?:?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}?)))?(??:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(??:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD"

and has a copyright.

Copyright © Michael Rushton 2009-10
http://squiloople.com/
Feel free to use and redistribute this code. But please keep this copyright notice.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.