Skip to content

Commit

Permalink
Added disposable and free email APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
MailboxValidator committed Sep 20, 2018
1 parent af16ff3 commit e0fe717
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 4 deletions.
137 changes: 134 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Add the following to your composer.json file:

```
"require": {
"mailboxvalidator/mailboxvalidator-php": "1.0.*"
"mailboxvalidator/mailboxvalidator-php": "1.1.*"
}
```

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


Usage
=====
Usage for validating emails
===========================

```php
<?php
Expand Down Expand Up @@ -195,6 +195,137 @@ The error code if there is any error. See error table below.

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


Usage for checking if an email is from a disposable email provider
==================================================================

```php
<?php
require_once __DIR__ . '/vendor/autoload.php';

use MailboxValidator\SingleValidation;

$mbv = new SingleValidation('PASTE_YOUR_API_KEY_HERE');

$results = $mbv->DisposableEmail('[email protected]');

if ($results === false) {
echo "Error connecting to API.\n";
}
else if (trim($results->error_code) == '') {
echo 'email_address = ' . $results->email_address . "\n";
echo 'is_disposable = ' . $results->is_disposable . "\n";
echo 'credits_available = ' . $results->credits_available . "\n";
}
else {
echo 'error_code = ' . $results->error_code . "\n";
echo 'error_message = ' . $results->error_message . "\n";
}
?>
```

Functions
=========

### SingleValidation(api_key)

Creates a new instance of the MailboxValidator object with the API key.

### DisposableEmail(email_address)

Check if the supplied email address is from a disposable email provider.

Result Fields
=============

### email_address

The input email address.

### is_disposable

Whether the email address is a temporary one from a disposable email provider.

Return values: True, False

### credits_available

The number of credits left to perform validations.

### error_code

The error code if there is any error. See error table below.

### error_message

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


Usage for checking if an email is from a free email provider
============================================================

```php
<?php
require_once __DIR__ . '/vendor/autoload.php';

use MailboxValidator\SingleValidation;

$mbv = new SingleValidation('PASTE_YOUR_API_KEY_HERE');

$results = $mbv->FreeEmail('[email protected]');

if ($results === false) {
echo "Error connecting to API.\n";
}
else if (trim($results->error_code) == '') {
echo 'email_address = ' . $results->email_address . "\n";
echo 'is_free = ' . $results->is_free . "\n";
echo 'credits_available = ' . $results->credits_available . "\n";
}
else {
echo 'error_code = ' . $results->error_code . "\n";
echo 'error_message = ' . $results->error_message . "\n";
}
?>
```

Functions
=========

### SingleValidation(api_key)

Creates a new instance of the MailboxValidator object with the API key.

### FreeEmail(email_address)

Check if the supplied email address is from a free email provider.

Result Fields
=============

### email_address

The input email address.

### is_free

Whether the email address is from a free email provider like Gmail or Hotmail.

Return values: True, False

### credits_available

The number of credits left to perform validations.

### error_code

The error code if there is any error. See error table below.

### error_message

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


Errors
======

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"MailboxValidator\\": "src/"
}
},
"version": "1.0.0"
"version": "1.1.0"
}
48 changes: 48 additions & 0 deletions src/SingleValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class SingleValidation {
private $apikey = '';
private $apiurl = 'http://api.mailboxvalidator.com/v1/validation/single';
private $apiurl2 = 'http://api.mailboxvalidator.com/v1/email/disposable';
private $apiurl3 = 'http://api.mailboxvalidator.com/v1/email/free';

public function __construct($key) {
$this->apikey = $key;
Expand Down Expand Up @@ -34,5 +36,51 @@ public function ValidateEmail($email) {
return false;
}
}

public function DisposableEmail($email) {
try{
$params = [ 'email' => $email, 'key' => $this->apikey, 'format' => 'json' ];
$params2 = [];
foreach($params as $key => $value) {
$params2[] = $key . '=' . rawurlencode($value);
}
$params = implode('&', $params2);

$results = file_get_contents($this->apiurl2 . '?' . $params);

if ($results !== false) {
return json_decode($results);
}
else {
return false;
}
}
catch(Exception $e) {
return false;
}
}

public function FreeEmail($email) {
try{
$params = [ 'email' => $email, 'key' => $this->apikey, 'format' => 'json' ];
$params2 = [];
foreach($params as $key => $value) {
$params2[] = $key . '=' . rawurlencode($value);
}
$params = implode('&', $params2);

$results = file_get_contents($this->apiurl3 . '?' . $params);

if ($results !== false) {
return json_decode($results);
}
else {
return false;
}
}
catch(Exception $e) {
return false;
}
}
}
?>

0 comments on commit e0fe717

Please sign in to comment.