Cupidvogel Posted April 14, 2012 Share Posted April 14, 2012 Hi, suppose I want to write a PHP script that checks whether a valid email address exists or not. There are a number of GUI-based tools to verify this, but is there any command line tool to do the same so that I can use PHP to capture the output? Quote Link to comment https://forums.phpfreaks.com/topic/260912-command-line-app-to-verify-whether-an-email-id-exists-or-not/ Share on other sites More sharing options...
requinix Posted April 14, 2012 Share Posted April 14, 2012 Define "exists". And any particular reason it has to be used via the command line (as opposed to a normal script you'd use in a webpage)? Quote Link to comment https://forums.phpfreaks.com/topic/260912-command-line-app-to-verify-whether-an-email-id-exists-or-not/#findComment-1337265 Share on other sites More sharing options...
Cupidvogel Posted April 14, 2012 Author Share Posted April 14, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/260912-command-line-app-to-verify-whether-an-email-id-exists-or-not/#findComment-1337267 Share on other sites More sharing options...
requinix Posted April 14, 2012 Share Posted April 14, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260912-command-line-app-to-verify-whether-an-email-id-exists-or-not/#findComment-1337269 Share on other sites More sharing options...
Cupidvogel Posted April 14, 2012 Author Share Posted April 14, 2012 Okay... Quote Link to comment https://forums.phpfreaks.com/topic/260912-command-line-app-to-verify-whether-an-email-id-exists-or-not/#findComment-1337270 Share on other sites More sharing options...
MMDE Posted April 14, 2012 Share Posted April 14, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260912-command-line-app-to-verify-whether-an-email-id-exists-or-not/#findComment-1337272 Share on other sites More sharing options...
Cupidvogel Posted April 14, 2012 Author Share Posted April 14, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/260912-command-line-app-to-verify-whether-an-email-id-exists-or-not/#findComment-1337273 Share on other sites More sharing options...
MMDE Posted April 14, 2012 Share Posted April 14, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260912-command-line-app-to-verify-whether-an-email-id-exists-or-not/#findComment-1337276 Share on other sites More sharing options...
requinix Posted April 14, 2012 Share Posted April 14, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260912-command-line-app-to-verify-whether-an-email-id-exists-or-not/#findComment-1337416 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.