Techno Blender
Digitally Yours.

How to check if an email address exists without sending an email ?

0 28


In this article, we will learn to check if an address exists without sending an email.

Approach: By using some free APIs we can easily check whether an email is valid or not. One of the easiest way to check whether an email address is valid is to use PHP’s filter_var() function.

Example 1:The following method can only check if the format is a valid email format. In this, we cannot check whether the format actually exits or not.

PHP

<?php

    

    $email1 = "[email protected]"

    

    $email2 = "gfg.com"

  

    

    function checkIfValid($email){

      if(filter_var($email , FILTER_VALIDATE_EMAIL) ){

        echo "Email is Valid\n";

      }

      else{

        echo "Email is not valid\n";

      }

    }

  

    checkIfValid($email1);

    checkIfValid($email2);

?>

Output
Email is Valid
Email is not valid

Example 2: To check if an email exists, we need to use some APIs into our PHP program. We are going to use a free API called abstractapi. The curl_init() function returns a cURL handle. The curl_setopt() set an option for a cURL transfer. The curl_setopt_array() sets multiple options for a cURL transfer. This function is useful for setting a large number of cURL options without repetitively calling curl_setopt().

PHP

<?php

  

    $email = '[email protected]';

  

    

    if(!filter_var($email , FILTER_VALIDATE_EMAIL)){

      exit("Invalid");

    }

  

    echo "Valid Email format\n";

    

    $ch = curl_init();

  

    

    

    $apiKey = "5f92aa70f05f4b8eb45e6d6f09ec8a08"

      

  

    curl_setopt_array($ch, [

        

        

        

        CURLOPT_URL => "https:

        api_key=$apiKey&email=$email",

          

        

        

        CURLOPT_RETURNTRANSFER => true,

        

        

        CURLOPT_FOLLOWLOCATION => true

        

    ]);

  

    

    $res = curl_exec($ch);

  

    

    curl_close($ch);

  

    $data = json_decode($res , true);

  

    if($data['deliverability'] === 'UNDELIVERABLE'){

      exit("EmailID $email does not exist");

    }

    exit("EmailID $email exists");

Output
Valid Email format
EmailID [email protected] exists

If we execute the command

echo $res ;

It contains all the information about our email

Output
{"email":"[email protected]","autocorrect":"","deliverability":"DELIVERABLE","quality_score":"0.70","is_valid_format":{"value":true,"text":"TRUE"},"is_free_email":{"value":true,"text":"TRUE"},"is_disposable_email":{"value":false,"text":"FALSE"},"is_role_email":{"value":false,"text":"FALSE"},"is_catchall_email":{"value":false,"text":"FALSE"},"is_mx_found":{"value":true,"text":"TRUE"},"is_smtp_valid":{"value":true,"text":"TRUE"}}

Example 3: We can also check the value of  $data[‘is_smtp_valid’][‘value’]  to check whether the email exists or not

PHP

<?php

  

    $email = '[email protected]';

  

    

    if(!filter_var($email , FILTER_VALIDATE_EMAIL)){

      exit("Invalid");

    }

  

    echo "Valid Email format\n";

    

    $ch = curl_init();

  

    

    

    $apiKey = "5f92aa70f05f4b8eb45e6d6f09ec8a08"

  

    curl_setopt_array($ch, [

        

        

        

        CURLOPT_URL => "https:

        api_key=$apiKey&email=$email",

          

        

        

        CURLOPT_RETURNTRANSFER => true,

        

        

        CURLOPT_FOLLOWLOCATION => true

        

    ]);

  

    

    $res = curl_exec($ch);

  

    

    curl_close($ch);

  

    $data = json_decode($res , true);

  

    if($data['is_smtp_valid']['value']){

      exit("EmailID $email does not exist");

    }

    exit("EmailID $email exists");

Output
Valid Email format
EmailID [email protected] exists


In this article, we will learn to check if an address exists without sending an email.

Approach: By using some free APIs we can easily check whether an email is valid or not. One of the easiest way to check whether an email address is valid is to use PHP’s filter_var() function.

Example 1:The following method can only check if the format is a valid email format. In this, we cannot check whether the format actually exits or not.

PHP

<?php

    

    $email1 = "[email protected]"

    

    $email2 = "gfg.com"

  

    

    function checkIfValid($email){

      if(filter_var($email , FILTER_VALIDATE_EMAIL) ){

        echo "Email is Valid\n";

      }

      else{

        echo "Email is not valid\n";

      }

    }

  

    checkIfValid($email1);

    checkIfValid($email2);

?>

Output
Email is Valid
Email is not valid

Example 2: To check if an email exists, we need to use some APIs into our PHP program. We are going to use a free API called abstractapi. The curl_init() function returns a cURL handle. The curl_setopt() set an option for a cURL transfer. The curl_setopt_array() sets multiple options for a cURL transfer. This function is useful for setting a large number of cURL options without repetitively calling curl_setopt().

PHP

<?php

  

    $email = '[email protected]';

  

    

    if(!filter_var($email , FILTER_VALIDATE_EMAIL)){

      exit("Invalid");

    }

  

    echo "Valid Email format\n";

    

    $ch = curl_init();

  

    

    

    $apiKey = "5f92aa70f05f4b8eb45e6d6f09ec8a08"

      

  

    curl_setopt_array($ch, [

        

        

        

        CURLOPT_URL => "https:

        api_key=$apiKey&email=$email",

          

        

        

        CURLOPT_RETURNTRANSFER => true,

        

        

        CURLOPT_FOLLOWLOCATION => true

        

    ]);

  

    

    $res = curl_exec($ch);

  

    

    curl_close($ch);

  

    $data = json_decode($res , true);

  

    if($data['deliverability'] === 'UNDELIVERABLE'){

      exit("EmailID $email does not exist");

    }

    exit("EmailID $email exists");

Output
Valid Email format
EmailID [email protected] exists

If we execute the command

echo $res ;

It contains all the information about our email

Output
{"email":"[email protected]","autocorrect":"","deliverability":"DELIVERABLE","quality_score":"0.70","is_valid_format":{"value":true,"text":"TRUE"},"is_free_email":{"value":true,"text":"TRUE"},"is_disposable_email":{"value":false,"text":"FALSE"},"is_role_email":{"value":false,"text":"FALSE"},"is_catchall_email":{"value":false,"text":"FALSE"},"is_mx_found":{"value":true,"text":"TRUE"},"is_smtp_valid":{"value":true,"text":"TRUE"}}

Example 3: We can also check the value of  $data[‘is_smtp_valid’][‘value’]  to check whether the email exists or not

PHP

<?php

  

    $email = '[email protected]';

  

    

    if(!filter_var($email , FILTER_VALIDATE_EMAIL)){

      exit("Invalid");

    }

  

    echo "Valid Email format\n";

    

    $ch = curl_init();

  

    

    

    $apiKey = "5f92aa70f05f4b8eb45e6d6f09ec8a08"

  

    curl_setopt_array($ch, [

        

        

        

        CURLOPT_URL => "https:

        api_key=$apiKey&email=$email",

          

        

        

        CURLOPT_RETURNTRANSFER => true,

        

        

        CURLOPT_FOLLOWLOCATION => true

        

    ]);

  

    

    $res = curl_exec($ch);

  

    

    curl_close($ch);

  

    $data = json_decode($res , true);

  

    if($data['is_smtp_valid']['value']){

      exit("EmailID $email does not exist");

    }

    exit("EmailID $email exists");

Output
Valid Email format
EmailID [email protected] exists

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – [email protected]. The content will be deleted within 24 hours.
Leave a comment