-
Notifications
You must be signed in to change notification settings - Fork 0
/
php-email-validation-sample.php
67 lines (54 loc) · 2.04 KB
/
php-email-validation-sample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
// create a free acount at https://app.sendbridge.com/signup
// and get your own API key
// more info in integration https://sendbridge.com/email-validation-api
$url = "https://api.sendbridge.com/v1/validate/hLxD5h0erBiqmPRbkrjJu4WBdRJI9lMi/tested@emailabc123.com";
// Initialize cURL
$curl = curl_init($url);
// Set cURL options
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Execute cURL request
$response = curl_exec($curl);
// Check for errors
if(curl_errno($curl)){
echo 'Error: ' . curl_error($curl);
exit;
}
// Close cURL
curl_close($curl);
// Decode JSON response
$json = json_decode($response, true);
// Check if JSON decoding was successful
if(json_last_error() !== JSON_ERROR_NONE){
echo 'Error: Failed to decode JSON response';
exit;
}
// Extract data from JSON response
$email = $json['email'];
$freemail = $json['freemail'];
$valid_syntax = $json['valid_syntax'];
$abnormal_local_part = $json['abnormal_local_part'];
$abnormal_domain = $json['abnormal_domain'];
$local_part_too_long = $json['local_part_too_long'];
$shared = $json['shared'];
$valid_tld = $json['valid_tld'];
$disposable = $json['disposable'];
$mx_valid = $json['mx_valid'];
$a_valid = $json['a_valid'];
$score = $json['score'];
$time_taken = $json['time_taken'];
// Print extracted data
echo "Email: " . $email . PHP_EOL;
echo "Free Email: " . ($freemail ? 'true' : 'false') . PHP_EOL;
echo "Valid Syntax: " . ($valid_syntax ? 'true' : 'false') . PHP_EOL;
echo "Abnormal Local Part: " . ($abnormal_local_part ? 'true' : 'false') . PHP_EOL;
echo "Abnormal Domain: " . ($abnormal_domain ? 'true' : 'false') . PHP_EOL;
echo "Local Part Too Long: " . ($local_part_too_long ? 'true' : 'false') . PHP_EOL;
echo "Shared: " . ($shared ? 'true' : 'false') . PHP_EOL;
echo "Valid TLD: " . ($valid_tld ? 'true' : 'false') . PHP_EOL;
echo "Disposable: " . ($disposable ? 'true' : 'false') . PHP_EOL;
echo "MX Valid: " . ($mx_valid ? 'true' : 'false') . PHP_EOL;
echo "A Valid: " . $a_valid . PHP_EOL;
echo "Score: " . $score . PHP_EOL;
echo "Time Taken: " . $time_taken . PHP_EOL;
?>