1

I'm attempting to check if an exists but false is always returned even though my email address exists.

function EmailValidation($email)
 { 
    $email = htmlspecialchars(stripslashes(strip_tags($email))); //parse unnecessary characters to prevent exploits

    if (filter_var($email, FILTER_VALIDATE_EMAIL)) 
    { //checks to make sure the email address is in a valid format
    $domain = explode( "@", $email ); //get the domain name
        if ( @fsockopen ($email,80,$errno,$errstr,3)) 
        {
            //if the connection can be established, the email address is probably valid
            return "yes";
        } else 
        {
            return "no"; //if a connection cannot be established return false
        }
    //return "not valid"; //if email address is an invalid format return false
  }
}

 $ve = EmailValidation("myemail@gmail.com");

print_r($ve);

I have 500k emails, i've been given the task to find out, which emails exist and which don't. I don't want to send an email but check if the email is exist. How do i solve?

mdnba50
  • 369
  • 4
  • 23
  • I have 500k emails, i've been given the task to find out, which emails exist and which don't. – mdnba50 Nov 22 '17 at 11:34
  • 1
    @mdnba50 There's no way you can figure out if they exist or not unless you try to send a mail to all of them and then you can figure out which ones bounce (however, not all email servers will bounce the email - some might accept it and throw it out, so you won't know that _they_ don't exist). – h2ooooooo Nov 22 '17 at 11:36
  • Check this https://stackoverflow.com/questions/19261987/how-to-check-if-an-email-address-is-real-or-valid-using-php – Ankur Tiwari Nov 22 '17 at 11:36
  • A webserver running on the same domain is a poor indicator. I have several domains set for receiving emails - none of them host a website. – James Thorpe Nov 22 '17 at 11:37
  • https://www.email-validator.net/email-address-online-verification-api.html it is an api provider which checks 100 email free. – Anand Pandey Nov 22 '17 at 11:49
  • https://www.mailgun.com/ – Anand Pandey Nov 22 '17 at 12:00

1 Answers1

2

It is impossible to check if an email address exists. Checking the host availability is also negligible because the biggest part of users use a good and reliable mail provider.

The only thing you can do, beside email name string validations, is to send an email to every entry and see if you will receive any error email back. Most provider give you a undeliverable message when the email doesn't exist anymore. But this can happen after 1 minute, after 1 hours, after 1 day or anytime later.

Conclusion: It's impossible to check if email addresses really exist.

Brain Foo Long
  • 2,057
  • 23
  • 28