secret
Created

  • Download Gist
briteverify.php
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
#!/usr/bin/php
<?php
$apikey="<PUT YOUR KEY HERE>";
 
/*
* Make sure args are passed
*/
if($argc!=2) {
print "Usage: ".$argv[0]." emailaddress@domain.com\n";
exit(1);
}
 
/*
* Set up cURL
*/
$c=curl_init("http://api.briteverify.com/emails/verify.js?apikey=$apikey&email[address]=".urlencode($argv[1]));
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FAILONERROR, false);
curl_setopt($c, CURLOPT_TIMEOUT, 5);
 
/*
* Run cURL, parse info, and close it
*/
$results=curl_exec($c);
$info=curl_getinfo($c);
curl_close($c);
 
/*
* decode the JSON results
*/
$answer=json_decode($results);
 
 
/*
* Make sure you have a valid HTTP status code, and it parsed into the expected JSON object
*/
if($info['http_code'] && isset($answer->email)) {
print "The email ".$argv[1]." has a status of: ".$answer->email->status."\n";
if($answer->email->status=="invalid") {
print "Address is invalid, encourage your user to correct his or her address\n";
} else {
print "Permit the user through\n";
}
} else {
print "Could not talk to BV servers - allow the address through as 'unknown'\n";
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.