Skip to content

Instantly share code, notes, and snippets.

@elclanrs
Created September 15, 2012 03:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elclanrs/301f4298189203b2fc77 to your computer and use it in GitHub Desktop.
Save elclanrs/301f4298189203b2fc77 to your computer and use it in GitHub Desktop.
#!/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";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment