6

How to check whether an email id exists or not using PHP? and to get information about the owner of the email id? is it possible to get the information about the owner of the email id? do have to work with some protocols like POP? Please help me.

drudge
  • 35,471
  • 7
  • 34
  • 45
brainless
  • 5,698
  • 16
  • 59
  • 82
  • 1
    I'm assuming by "id", you mean "address". Why do you want to do this? While I'm sure there are plenty of valid uses cases, it sounds spam-ish to me. – brettkelly Jan 12 '11 at 00:34
  • @inkedmn: i wish to use it in website's registration page for verifying email addresses in-order to prevent spam and fake registrations! absolutely for fraud detection! – brainless Jan 12 '11 at 00:38
  • Sending an activation link is about your only option. – drudge Jan 12 '11 at 00:40
  • This isn't possible in the way you are looking to do it. Verification e-mail is the only way. – Brad Jan 12 '11 at 01:04
  • Activation link is will confirm that the user owns the mailbox, not validate the mailbox exists. they are 2 separate entities. – RobertPitt Jan 12 '11 at 01:09
  • @RobertPitt: they can only own the mail box if it exists. I'm sure there are some cases where someone wouldn't care if the person who submitted the email address is the owner of said address, in which case what you have in your answer is useful, but still doesn't promise 100% accuracy. – Brian Ball Jan 12 '11 at 01:53

2 Answers2

13

There is no 100% guaranteed way of knowing if an email address is valid without sending an email and having the user respond in some way. There are checks you can do to increase the chances of knowing if an email address is valid or not. You can do a DNS lookup and see if the domain has an MX record. There are also parts of the SMTP protocol you can use, but nothing mandates that an SMTP server will respond to these commands. Centralops.net provides a product that can help, but again, it isn't guaranteed.

If there was a sure way of handling this, then why would virtually every site that has a registration feature require you to respond to an email in some way? The question isn't meant to be a snide one; I'm just hoping it helps you see that other sites have not been able to perform the very same check you are asking for.

HTH

Brian Ball
  • 12,268
  • 3
  • 40
  • 51
  • 1
    i came across a link while googling. http://www.verifyemailaddress.org/ . how could have they done it? i think they did it well. – brainless Jan 12 '11 at 00:47
  • 1
    But there is no way to be positive. You can do the steps outlined by RobertPitt, some of what he lists I have in my answer (though he explains in greater detail), but end of the day, the only way to know for sure is by actually sending an email, and making the user respond to it in some way. Some SMTP servers will tell you the email address doesn't exist right away, but others simply accept the email and then it dies off in the ether. Many SMTP servers won't respond to the command of asking if an email address exists. They have turned this off to deter spamming. – Brian Ball Jan 12 '11 at 01:49
  • 4
    verifyemailaddress.org does not actually work. It just checks for MX records or something I just tried a search for "dfdfasdfsdfasdf32432@hotmail.com" told me it was valid. Went to hotmail and that address is available... – Mike L. Jan 12 '11 at 02:14
12

Lets say a user submits the following email address:

  • stackuser@stackoverflow.com

The checks you would want to perform in order are like so:

  • Is the address valid
  • Does the domain run a mail server / MX Records
  • Is it blacklisted

Firstly within PHP you can validate an email by using filter_var like so:

$is_valid = filter_var("stackuser@stackoverflow.com",FILTER_VALIDATE_EMAIL);

Secondly you would want to check if the domain runs a email server, to do this you can check the dns records for MX like so:

$has_dns_mx_record = checkdnsrr("stackoverflow.com","MX");

You might also want to open the port on the domain like so:

$socket = fsockopen("stackoverflow.com", 25);
$mail_running = (bool)$socket;
fclose($socket);

You can also check to see if the SMTP Server responds with a 550, i.e email does not exist, like so:

SEND > helo hi
250 stackoverflow.com

SEND > mail from: <youremail@yoursite.com>
250 2.1.0 Ok

SEND > rcpt to: <stackuser@stackoverflow.com>
> 550 5.1.1 <stackuser@stackoverflow.com>: Recipient address rejected: User unknown in local recipient table

Looking at the above you can send commands to a valid smtp server such as helo > mail from <...> and check the 550 response.

Take a look here for some response codes: http://www.greenend.org.uk/rjk/2000/05/21/smtp-replies.html

Also you should take note of @slebetman's comment stating that a small percentage of mail > servers are configured to respond 550 to prevent the sniffing out of valid email addresses.

The black list check is pretty simple, you would just find a decent DNSBL Server that provides a gateway for you check check the domain to see if it has been blacklisted, if it has the email may well be valid and active but has been marked as spam, therefore its an untrusted email and you should request an alternative email address to authorize against

These are some of the validation techniques used to validate an email address, now there is plenty more validation methods but these are a few of the main ones.

SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62
RobertPitt
  • 56,863
  • 21
  • 114
  • 161
  • 4
    This has a 99% chance of working. There are some mail servers that is configured to never return 550 response so that scripts cannot sniff out valid email address. My own email server is configured like this. So is Yahoo mail. – slebetman Jan 12 '11 at 01:44