Skip to content

Commit 5d083b7

Browse files
committed
v0.1.0
0 parents  commit 5d083b7

23 files changed

+1170
-0
lines changed

.env.example.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
EMAIL_VALIDATION_API_KEY="YOUR_API_KEY"

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/tests export-ignore
2+
/.gitattributes export-ignore
3+
/.gitignore export-ignore

.github/workflows/unittest.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Unit test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
unit_test:
7+
runs-on: ${{ matrix.operating-system }}
8+
strategy:
9+
matrix:
10+
operating-system: [ ubuntu-18.04, windows-2019 ]
11+
php: [ '7.1', '7.2', '7.3', '7.4', '7.3.3' ]
12+
13+
env:
14+
EMAIL_VALIDATION_API_KEY: ${{ secrets.API_KEY }}
15+
16+
steps:
17+
- uses: actions/checkout@master
18+
19+
- name: Setup PHP
20+
uses: nanasess/setup-php@master
21+
with:
22+
php-version: ${{ matrix.php }}
23+
24+
- name: Run test
25+
run: |
26+
composer self-update
27+
composer install --prefer-source --no-interaction --ignore-platform-reqs
28+
php vendor/bin/phpunit

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Environment files
2+
.env
3+
.env.test
4+
5+
# Composer
6+
/vendor
7+
composer.phar
8+
composer.lock

.scrutinizer.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# .scrutinizer.yml
2+
checks:
3+
php: true
4+
5+
filter:
6+
excluded_paths:
7+
- tests/*
8+
- vendor/*
9+
paths:
10+
- src/*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Abstract
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# AbstractAPI php-email-validation library
2+
3+
[![Build Status](https://travis-ci.com/abstractapi/php-email-validation.png?branch=main)](https://travis-ci.com/abstractapi/php-email-validation)
4+
[![Packagist](https://img.shields.io/packagist/v/abstractapi/php-email-validation.svg)](https://packagist.org/packages/abstractapi/php-email-validation)
5+
[![Packagist](https://img.shields.io/packagist/dt/abstractapi/php-email-validation.svg)](https://packagist.org/packages/abstractapi/php-email-validation)
6+
7+
Integrate the powerful [email validation API from Abstract](https://www.abstractapi.com/email-verification-validation-api) in your PHP project in a few lines of code.
8+
9+
Abstract's Email Validation and Verification API is a fast, lightweight, modern, and RESTful JSON API for determining the validity and other details of email addresses.
10+
11+
It's very simple to use: you only need to submit your API key and an email address, and the API will respond an assessment of its validity, as well as additional details like quality score if it's a disposable email, a catchall address, and more.
12+
13+
Validating and verifying email addresses is a critical step to reducing the chances of low-quality data and fraudulent or risky users in your website or application.
14+
15+
# Documentation
16+
17+
## Supported PHP Versions
18+
19+
This library supports the **PHP version 5.6** and higher.
20+
21+
## Installation
22+
23+
You can install **php-email-validation** via composer or by downloading the source.
24+
25+
### Via Composer:
26+
27+
**php-email-validation** is available on Packagist as the
28+
[`abstractapi/php-email-validation`](https://packagist.org/packages/abstractapi/php-email-validation) package:
29+
30+
```bash
31+
composer require abstractapi/php-email-validation
32+
```
33+
34+
## API key
35+
36+
Get your API key for free and without hassle from the [Abstact website](https://app.abstractapi.com/users/signup?target=/api/email-validation/pricing/select).
37+
38+
## Quickstart
39+
40+
### Verify email
41+
42+
```php
43+
// Verify email using Abstract's Email Validation and Verification API and PHP
44+
<?php
45+
$api_key = "YYYYYY"; // Get your API Key from https://app.abstractapi.com/api/email-validation/documentation
46+
47+
Abstractapi\EmailValidation\AbstractEmailValidation::configure($api_key);
48+
49+
$info = Abstractapi\EmailValidation\AbstractEmailValidation::verify('[email protected]');
50+
51+
print $info->quality_score;
52+
```
53+
54+
## API response
55+
56+
The API response is returned in a `EmailValidationData` object.
57+
58+
| PARAMETER | TYPE | DETAILS |
59+
| - | - | - |
60+
| email | String | The value for "email" that was entered into the request. |
61+
| auto_correct | String | If a typo has been detected then this parameter returns a suggestion of the correct email (e.g., [email protected] => [email protected]). If no typo is detected then this is empty. |
62+
| deliverability | String | Abstract's evaluation of the deliverability of the email. Possible values are: DELIVERABLE, UNDELIVERABLE, RISKY, and UNKNOWN |
63+
| quality_score | Number | An internal decimal score between 0.01 and 0.99 reflecting Abstract's confidence in the quality and deliverability of the submitted email. |
64+
| is_valid_format | Boolean | Is true if the email follows the format of "address @ domain . TLD". If any of those elements are missing or if they contain extra or incorrect special characters, then it returns false. |
65+
| is_free_email | Boolean | Is true if the email's domain is found among Abstract's list of free email providers (e.g., Gmail, Yahoo, etc). |
66+
| is_disposable_email | Boolean | Is true if the email's domain is found among Abstract's list of disposable email providers (e.g., Mailinator, Yopmail, etc). |
67+
| is_role_email | Boolean | Is true if the email's local part (e.g., the "to" part) appears to be for a role rather than individual. Examples of this include "team@", "sales@", info@", etc. |
68+
| is_catchall_email | Boolean | Is true if the domain is configured to catch all email. |
69+
| is_mx_found | Boolean | Is true if MX Records for the domain can be found. Only available on paid plans. Will return null and UNKNOWN on free plans. |
70+
| is_smtp_valid | Boolean | Is true is the SMTP check of the domain was successful. Only available on paid plans. Will return null and UNKNOWN on free plans. |
71+
72+
## Detailed documentation
73+
74+
You will find additional information and request examples in the [Abstract help page](https://app.abstractapi.com/api/email-validation/documentation).
75+
76+
## Getting help
77+
78+
If you need help installing or using the library, please contact [Abstract's Support](https://app.abstractapi.com/api/email-validation/support).
79+
80+
For bug report and feature suggestion, please use [this repository issues page](https://github.com/abstractapi/php-email-validation/issues).
81+
82+
# Contribution
83+
84+
Contributions are always welcome, as they improve the quality of the libraries we provide to the community.
85+
86+
Please provide your changes covered by the appropriate unit tests, and post them in the [pull requests page](https://github.com/abstractapi/php-email-validation/pulls).
87+
88+
## Composer
89+
90+
To work on the source code, you need to install composer on your local computer. At the time of writing, the latest version of composer is v2.0.12. The installation instructions can be found here: https://getcomposer.org/download/.
91+
92+
## Setup
93+
94+
To install the requirements, run:
95+
96+
```bash
97+
composer install --prefer-source --no-interaction --ignore-platform-reqs
98+
```
99+
100+
Once you implementer all your changes and the unit tests, run the following command to run the tests:
101+
102+
```bash
103+
php vendor/bin/phpunit
104+
```

composer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "abstractapi/php-email-validation",
3+
"description": "AbstractEmailValidation - Wrapper to quickly start using the powerful AbstractAPI's email validation service in your projects.",
4+
"version": "0.1.0",
5+
"type": "library",
6+
"keywords": ["php", "api", "abstract", "abstractapi", "email", "emailvalidation", "email validation", "email verification", "wrapper", "library"],
7+
"homepage": "https://github.com/abstractapi/php-email-validation",
8+
"readme": "README.md",
9+
"time": "2021-04-09",
10+
"license": "MIT",
11+
"authors": [
12+
{
13+
"name": "Benjamin Bouchet",
14+
"email": "[email protected]",
15+
"homepage": "https://www.abstractapi.com"
16+
}
17+
],
18+
"support": {
19+
"source": "https://github.com/abstractapi/php-email-validation",
20+
"docs": "https://app.abstractapi.com/api/email-validation/documentation"
21+
},
22+
"scripts": {
23+
"check": [
24+
],
25+
"fix": [
26+
],
27+
"versions": [
28+
]
29+
},
30+
"require": {
31+
"php": ">=5.6",
32+
"ext-curl": "*",
33+
"ext-json": "*"
34+
},
35+
"require-dev": {
36+
"phpunit/phpunit": "7.0.*",
37+
"vlucas/phpdotenv": "^2.0"
38+
},
39+
"suggest": {
40+
},
41+
"autoload": {
42+
"psr-4": {
43+
"Abstractapi\\EmailValidation\\": "src/AbstractEmailValidation/"
44+
}
45+
},
46+
"autoload-dev": {
47+
"psr-4": {
48+
"Abstractapi\\EmailValidation\\Tests\\": "tests/"
49+
}
50+
}
51+
}

examples/error_handling.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
require_once("../src/AbstractEmailValidation/autoload.php");
4+
5+
use Abstractapi\EmailValidation\AbstractEmailValidation;
6+
use Abstractapi\EmailValidation\Common\Exception\AbstractHttpErrorException;
7+
8+
AbstractEmailValidation::configure($api_key = "YOUR_API_KEY");
9+
10+
try
11+
{
12+
$info = AbstractEmailValidation::verify('[email protected]');
13+
}
14+
catch (AbstractHttpErrorException $e)
15+
{
16+
echo "Message: ". $e->getMessage(). "; <br>";
17+
echo "Code: ". $e->code. "; <br>";
18+
echo "HttpStatusCode: ". $e->http_code. "; <br>";
19+
echo "Details: ";
20+
print_r($e->details);
21+
22+
echo "<pre>";
23+
print_r(AbstractEmailValidation::getLastResponse());
24+
echo "</pre>";
25+
}
26+
catch (InvalidArgumentException $e)
27+
{
28+
// Handle somehow
29+
}

examples/verify_email.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
require_once("../src/AbstractEmailValidation/autoload.php");
4+
5+
use Abstractapi\EmailValidation\AbstractEmailValidation;
6+
7+
8+
AbstractEmailValidation::configure($api_key = "YOUR_API_KEY");
9+
10+
$info = AbstractEmailValidation::verify('[email protected]');
11+
12+
13+
echo "<pre>";
14+
print_r($info);
15+
echo "</pre>";
16+
17+
echo $info->quality_score;
18+
echo "</br>";
19+
echo var_export($info->is_catchall_email);
20+
echo "</br>";
21+
echo var_export($info->is_valid_format);
22+
echo "</br>";
23+
echo var_export($info->is_mx_found);
24+
echo "</br>";
25+
echo var_export($info->is_smtp_valid);

0 commit comments

Comments
 (0)