-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMG_Email.php
48 lines (38 loc) · 1.41 KB
/
MG_Email.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
<?php
// Quick (dirty) email validation using mailgun's api
// (http://documentation.mailgun.com/api-email-validation.html)
// Pre: You will need a public apikey from mailgun.
// ...Signup @ maigun.com/signup for one
// author: @kehers
class MG_Email {
var $key;
var $spell_check;
function __construct($key) {
$this->key = $key;
}
function is_valid($email) {
$response = json_decode($this->get('https://api.mailgun.net/v2/address/validate?address='.$email));
$this->spell_check = $response->did_you_mean ? $response->did_you_mean : '';
//var_dump($response);
return $response->is_valid ? true : false;
}
private function get($url) {
$url .= '&api_key='.$this->key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// set to 1 to verify ssl
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status != 200) {
// Something is wrong with the api,
// Revert to another verification method
// is_email (code.google.com/p/isemail/) maybe?
}
curl_close($ch);
return $response;
}
}
?>