Skip to content

Commit bf579b4

Browse files
committed
Add class & package infomation
1 parent d5a92c1 commit bf579b4

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "overint/php-mailgun-validation",
3+
"description": "Validate email address with Mailgun's validation service (Syntax checks, DNS validation, MX validation)",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "overint",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"minimum-stability": "stable",
13+
"require": {},
14+
"autoload": {
15+
"psr-4": {
16+
"overint\\": "src"
17+
}
18+
}
19+
}

src/MailgunValidator.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php namespace overint;
2+
3+
4+
class MailgunValidator
5+
{
6+
private $apiKey;
7+
8+
function __construct($apiKey)
9+
{
10+
$this->apiKey = $apiKey;
11+
}
12+
13+
private function queryMailgun($email)
14+
{
15+
$curl = curl_init();
16+
17+
curl_setopt_array($curl, array(
18+
CURLOPT_URL => "https://api.mailgun.net/v3/address/validate?api_key=" . $this->apiKey . "&address=" . $email,
19+
CURLOPT_RETURNTRANSFER => true,
20+
CURLOPT_MAXREDIRS => 0,
21+
CURLOPT_TIMEOUT => 30,
22+
));
23+
24+
$response = curl_exec($curl);
25+
$err = curl_error($curl);
26+
27+
curl_close($curl);
28+
29+
if ($err) {
30+
throw new Exception('Curl Error: ' . $err);
31+
} else {
32+
return json_decode($response);
33+
}
34+
}
35+
36+
public function validate($email)
37+
{
38+
$ret = $this->queryMailgun($email);
39+
return $ret->is_valid;
40+
}
41+
42+
public function validateExtended($email)
43+
{
44+
return $this->queryMailgun($email);
45+
}
46+
47+
48+
}

0 commit comments

Comments
 (0)