Skip to content

Commit e0fe717

Browse files
author
MailboxValidator
committed
Added disposable and free email APIs
1 parent af16ff3 commit e0fe717

3 files changed

Lines changed: 183 additions & 4 deletions

File tree

README.md

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Add the following to your composer.json file:
1717

1818
```
1919
"require": {
20-
"mailboxvalidator/mailboxvalidator-php": "1.0.*"
20+
"mailboxvalidator/mailboxvalidator-php": "1.1.*"
2121
}
2222
```
2323

@@ -30,8 +30,8 @@ An API key is required for this module to function.
3030
Go to https://www.mailboxvalidator.com/plans#api to sign up for FREE API plan and you'll be given an API key.
3131

3232

33-
Usage
34-
=====
33+
Usage for validating emails
34+
===========================
3535

3636
```php
3737
<?php
@@ -195,6 +195,137 @@ The error code if there is any error. See error table below.
195195

196196
The error message if there is any error. See error table below.
197197

198+
199+
Usage for checking if an email is from a disposable email provider
200+
==================================================================
201+
202+
```php
203+
<?php
204+
require_once __DIR__ . '/vendor/autoload.php';
205+
206+
use MailboxValidator\SingleValidation;
207+
208+
$mbv = new SingleValidation('PASTE_YOUR_API_KEY_HERE');
209+
210+
$results = $mbv->DisposableEmail('example@example.com');
211+
212+
if ($results === false) {
213+
echo "Error connecting to API.\n";
214+
}
215+
else if (trim($results->error_code) == '') {
216+
echo 'email_address = ' . $results->email_address . "\n";
217+
echo 'is_disposable = ' . $results->is_disposable . "\n";
218+
echo 'credits_available = ' . $results->credits_available . "\n";
219+
}
220+
else {
221+
echo 'error_code = ' . $results->error_code . "\n";
222+
echo 'error_message = ' . $results->error_message . "\n";
223+
}
224+
?>
225+
```
226+
227+
Functions
228+
=========
229+
230+
### SingleValidation(api_key)
231+
232+
Creates a new instance of the MailboxValidator object with the API key.
233+
234+
### DisposableEmail(email_address)
235+
236+
Check if the supplied email address is from a disposable email provider.
237+
238+
Result Fields
239+
=============
240+
241+
### email_address
242+
243+
The input email address.
244+
245+
### is_disposable
246+
247+
Whether the email address is a temporary one from a disposable email provider.
248+
249+
Return values: True, False
250+
251+
### credits_available
252+
253+
The number of credits left to perform validations.
254+
255+
### error_code
256+
257+
The error code if there is any error. See error table below.
258+
259+
### error_message
260+
261+
The error message if there is any error. See error table below.
262+
263+
264+
Usage for checking if an email is from a free email provider
265+
============================================================
266+
267+
```php
268+
<?php
269+
require_once __DIR__ . '/vendor/autoload.php';
270+
271+
use MailboxValidator\SingleValidation;
272+
273+
$mbv = new SingleValidation('PASTE_YOUR_API_KEY_HERE');
274+
275+
$results = $mbv->FreeEmail('example@example.com');
276+
277+
if ($results === false) {
278+
echo "Error connecting to API.\n";
279+
}
280+
else if (trim($results->error_code) == '') {
281+
echo 'email_address = ' . $results->email_address . "\n";
282+
echo 'is_free = ' . $results->is_free . "\n";
283+
echo 'credits_available = ' . $results->credits_available . "\n";
284+
}
285+
else {
286+
echo 'error_code = ' . $results->error_code . "\n";
287+
echo 'error_message = ' . $results->error_message . "\n";
288+
}
289+
?>
290+
```
291+
292+
Functions
293+
=========
294+
295+
### SingleValidation(api_key)
296+
297+
Creates a new instance of the MailboxValidator object with the API key.
298+
299+
### FreeEmail(email_address)
300+
301+
Check if the supplied email address is from a free email provider.
302+
303+
Result Fields
304+
=============
305+
306+
### email_address
307+
308+
The input email address.
309+
310+
### is_free
311+
312+
Whether the email address is from a free email provider like Gmail or Hotmail.
313+
314+
Return values: True, False
315+
316+
### credits_available
317+
318+
The number of credits left to perform validations.
319+
320+
### error_code
321+
322+
The error code if there is any error. See error table below.
323+
324+
### error_message
325+
326+
The error message if there is any error. See error table below.
327+
328+
198329
Errors
199330
======
200331

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
"MailboxValidator\\": "src/"
1919
}
2020
},
21-
"version": "1.0.0"
21+
"version": "1.1.0"
2222
}

src/SingleValidation.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
class SingleValidation {
44
private $apikey = '';
55
private $apiurl = 'http://api.mailboxvalidator.com/v1/validation/single';
6+
private $apiurl2 = 'http://api.mailboxvalidator.com/v1/email/disposable';
7+
private $apiurl3 = 'http://api.mailboxvalidator.com/v1/email/free';
68

79
public function __construct($key) {
810
$this->apikey = $key;
@@ -34,5 +36,51 @@ public function ValidateEmail($email) {
3436
return false;
3537
}
3638
}
39+
40+
public function DisposableEmail($email) {
41+
try{
42+
$params = [ 'email' => $email, 'key' => $this->apikey, 'format' => 'json' ];
43+
$params2 = [];
44+
foreach($params as $key => $value) {
45+
$params2[] = $key . '=' . rawurlencode($value);
46+
}
47+
$params = implode('&', $params2);
48+
49+
$results = file_get_contents($this->apiurl2 . '?' . $params);
50+
51+
if ($results !== false) {
52+
return json_decode($results);
53+
}
54+
else {
55+
return false;
56+
}
57+
}
58+
catch(Exception $e) {
59+
return false;
60+
}
61+
}
62+
63+
public function FreeEmail($email) {
64+
try{
65+
$params = [ 'email' => $email, 'key' => $this->apikey, 'format' => 'json' ];
66+
$params2 = [];
67+
foreach($params as $key => $value) {
68+
$params2[] = $key . '=' . rawurlencode($value);
69+
}
70+
$params = implode('&', $params2);
71+
72+
$results = file_get_contents($this->apiurl3 . '?' . $params);
73+
74+
if ($results !== false) {
75+
return json_decode($results);
76+
}
77+
else {
78+
return false;
79+
}
80+
}
81+
catch(Exception $e) {
82+
return false;
83+
}
84+
}
3785
}
3886
?>

0 commit comments

Comments
 (0)