Skip to content

Commit fbfff2c

Browse files
Initial
Initial
0 parents  commit fbfff2c

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
MailboxValidator PHP Module
2+
===========================
3+
4+
This PHP module provides an easy way to call the MailboxValidator API which validates if an email address is a valid one.
5+
6+
This module can be used in many types of projects such as:
7+
8+
- validating a user's email during sign up
9+
- cleaning your mailing list prior to an email marketing campaign
10+
- a form of fraud check
11+
12+
13+
Installation Using PHP Composer
14+
===============================
15+
16+
Add the following to your composer.json file:
17+
18+
```
19+
"require": {
20+
"mailboxvalidator/email-validation": "1.0.*"
21+
}
22+
```
23+
24+
25+
Dependencies
26+
============
27+
28+
An API key is required for this module to function.
29+
30+
Go to http://www.mailboxvalidator.com/plans#api to sign up for FREE API plan and you'll be given an API key.
31+
32+
33+
Sample Usage
34+
============
35+
36+
```php
37+
require_once __DIR__ . '/vendor/autoload.php';
38+
39+
use MailboxValidator\SingleValidation;
40+
41+
$mbv = new SingleValidation('PASTE_YOUR_API_KEY_HERE');
42+
43+
$results = $mbv->ValidateEmail('[email protected]');
44+
45+
if ($results === false) {
46+
echo "Error connecting to API.\n";
47+
}
48+
else if (trim($results->error_code) == '') {
49+
echo 'email_address = ' . $results->email_address . "\n";
50+
echo 'domain = ' . $results->domain . "\n";
51+
echo 'is_free = ' . $results->is_free . "\n";
52+
echo 'is_syntax = ' . $results->is_syntax . "\n";
53+
echo 'is_domain = ' . $results->is_domain . "\n";
54+
echo 'is_smtp = ' . $results->is_smtp . "\n";
55+
echo 'is_verified = ' . $results->is_verified . "\n";
56+
echo 'is_server_down = ' . $results->is_server_down . "\n";
57+
echo 'is_greylisted = ' . $results->is_greylisted . "\n";
58+
echo 'is_disposable = ' . $results->is_disposable . "\n";
59+
echo 'is_suppressed = ' . $results->is_suppressed . "\n";
60+
echo 'is_role = ' . $results->is_role . "\n";
61+
echo 'is_high_risk = ' . $results->is_high_risk . "\n";
62+
echo 'is_catchall = ' . $results->is_catchall . "\n";
63+
echo 'mailboxvalidator_score = ' . $results->mailboxvalidator_score . "\n";
64+
echo 'time_taken = ' . $results->time_taken . "\n";
65+
echo 'status = ' . $results->status . "\n";
66+
echo 'credits_available = ' . $results->credits_available . "\n";
67+
}
68+
else {
69+
echo 'error_code = ' . $results->error_code . "\n";
70+
echo 'error_message = ' . $results->error_message . "\n";
71+
}
72+
```
73+
74+
75+
Copyright
76+
=========
77+
78+
Copyright (C) 2017 by MailboxValidator.com, [email protected]

composer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "mailboxvalidator/email-validation",
3+
"description": "Validate an email address using the MailboxValidator API",
4+
"license": "LGPL-3.0",
5+
"keywords": ["mailboxvalidator","email validation"],
6+
"authors": [
7+
{
8+
"name": "MailboxValidator",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"MailboxValidator\\": "src/"
15+
}
16+
},
17+
"version": "1.0.0"
18+
}

src/SingleValidation.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php namespace MailboxValidator;
2+
3+
class SingleValidation {
4+
private $apikey = '';
5+
private $apiurl = 'http://api.mailboxvalidator.com/v1/validation/single';
6+
7+
public function __construct($key) {
8+
$this->apikey = $key;
9+
}
10+
11+
public function __destruct() {
12+
13+
}
14+
15+
public function ValidateEmail($email) {
16+
try{
17+
$params = [ 'email' => $email, 'key' => $this->apikey, 'format' => 'json' ];
18+
$params2 = [];
19+
foreach($params as $key => $value) {
20+
$params2[] = $key . '=' . rawurlencode($value);
21+
}
22+
$params = implode('&', $params2);
23+
24+
$results = file_get_contents($this->apiurl . '?' . $params);
25+
26+
if ($results !== false) {
27+
return json_decode($results);
28+
}
29+
else {
30+
return false;
31+
}
32+
}
33+
catch(Exception $e) {
34+
return false;
35+
}
36+
}
37+
}
38+
?>

0 commit comments

Comments
 (0)