SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict crabby80's Avatar
    Join Date
    May 2007
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can you test whether an email address exists from a PHP script?

    Hi guys

    Can you test whether an email address exists from a PHP script?

    For example if a person left their company and their email account was deleted, is there a way you can validate against this if they tried to login to the company website? I know the obvious answer is to just delete their user account, but could this be done as fail safe option.

    Thanks guys

    Crabby

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The only way you could do this would be to implement part of the SMTP and DNS specifications within your PHP script. You'd need to look up the MX server of the address's domain (DNS requests) to know what mail server handles it, open a socket connection on the SMTP port, start sending a message, and see if you get an error that the mailbox doesn't exist. Even this won't be foolproof as you dont' always get a mailbox error up front, and clearly this isn't a simple solution.

  3. #3
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,196
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    The only viable way is to check the MX record, but that is an expensive operation (as all dns lookups are) and it is not foolproof. "Talking" with the mailservers are not reliable enough to be used as verification, as placing the script on different locations can lead to different results, sometimes even refreshing could mean the difference of accepting or denying the account.

    If your interested in doing this you want to buy issue 6 2008 of the php architect magazine, there was a good article about how you can verify emails. http://www.phparch.com

  4. #4
    SitePoint Addict crabby80's Avatar
    Join Date
    May 2007
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your replies guys

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,836
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Most mail servers are set up to NOT tell you if email addresses exist.

    Those that are set up to tell you would have the email addresses that they confirm exist so swamped with spam that they would be useless for trying to use for real emails.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •