Skip to content

Commit 59448fc

Browse files
committed
Initial commit
0 parents  commit 59448fc

16 files changed

+5103
-0
lines changed

Diff for: .gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/vendor/
2+
.idea/
3+
.DS_Store
4+
.editorconfig
5+
.vscode
6+
.phpunit.cache
7+
.phpunit.result.cache

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Ray Hughes
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.

Diff for: README.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# sendgrid-validation
2+
[![Packagist](https://img.shields.io/packagist/v/rayhughes/sendgrid-validation.svg)](https://packagist.org/packages/rayhughes/sendgrid-validation)
3+
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg)](https://php.net/)
4+
[![Licensed under the MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/RayHughes/moneypot-api/blob/master/LICENSE)
5+
6+
A PHP library to validate email addresses using the Twilio SendGrid [Email Validation API](https://docs.sendgrid.com/ui/managing-contacts/email-address-validation).
7+
8+
## Prerequisites
9+
- Twilio SendGrid [Email Validation API Key](https://docs.sendgrid.com/ui/managing-contacts/email-address-validation#generating-your-email-validation-api-key)
10+
- PHP 7.4 or greater
11+
- [Composer](http://getcomposer.org/)
12+
13+
## Installation
14+
15+
```bash
16+
composer require rayhughes/sendgrid-validation
17+
```
18+
19+
## Usage
20+
21+
### Basic
22+
`EmailValidation()` initialized with default thresholds.
23+
```php
24+
use SendGridValidation\EmailValidation;
25+
use SendGridValidation\Service\SendGridService;
26+
27+
$validation = new EmailValidation(new SendGridService('api-key'));
28+
29+
print_r($validation->validate('[email protected]'));
30+
31+
/** Outputs
32+
SendGridValidation\Dto\EmailValidationDto
33+
(
34+
[isValid] => true
35+
[isValidRisk] => true
36+
[isValidScore] => true
37+
[isDisposable] => false
38+
[hasSuggestion] => false
39+
[suggestion] => null
40+
)
41+
**/
42+
````
43+
`EmailValidation()->validate()` returns an instance of `EmailValidationDto()`
44+
45+
#### EmailValidationDto()
46+
47+
- `$isValid` - Calculated `true` if validation result meets specified thresholds.
48+
- `$isValidRisk` - Calculated `true` specified risk criteria
49+
- `$isValidScore` - Calculated `true` if within minimum score threshold.
50+
- `$isDisposable` - Calculated `true` if an email is considered to be disposable.
51+
- `$hasSuggestion` - Calculated `true` if a suggestion is available.
52+
- `$suggestion` - Calculated email suggestion if available.
53+
54+
```php
55+
class EmailValidationDto
56+
{
57+
public bool $isValid = false;
58+
59+
public bool $isValidRisk = false;
60+
61+
public bool $isValidScore = false;
62+
63+
public bool $isDisposable = false;
64+
65+
public bool $hasSuggestion = false;
66+
67+
public ?string $suggestion = null;
68+
}
69+
```
70+
71+
### Advanced
72+
`EmailValidation()` can be initialized with optional parameters to validate against developer specified thresholds.
73+
74+
- `$allowRisky` - When `true`, considers risky emails `valid` if other conditions are met.
75+
- `$allowDisposable`- When `true`, considers disposable emails `valid` if other conditions are met.
76+
- `$checkValidScore` - When `true`, checks SendGrid `valid` emails against the minimum score threshold.
77+
- `$minSCore` - Default `0.30`. considers emails `invalid` if the minimum score threshold is not met.
78+
79+
```php
80+
use SendGridValidation\EmailValidation;
81+
use SendGridValidation\Service\SendGridService;
82+
83+
$validation = new EmailValidation(
84+
new SendGridService($apiKey),
85+
true, // bool $allowRisky = true,
86+
true, // bool $allowDisposable = true,
87+
true, // bool $checkValidScore = false,
88+
EmailValidation::MIN_SCORE // float $minScore = self::MIN_SCORE (0.30)
89+
);
90+
91+
$validation->validate($email);
92+
```

Diff for: composer.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "rayhughes/sendgrid-validation",
3+
"description": "A PHP library to validate email addresses using the Twilio SendGrid Email Validation API.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Ray Hughes"
9+
}
10+
],
11+
"keywords": [
12+
"sendgrid",
13+
"twilio sendGrid",
14+
"sendGrid email validation",
15+
"validation api",
16+
"email validation"
17+
],
18+
"require": {
19+
"php": "^7.4",
20+
"ext-json": "*",
21+
"ext-curl": "*",
22+
"ext-mbstring": "*",
23+
"guzzlehttp/guzzle": "^7.3"
24+
},
25+
"require-dev": {
26+
"vimeo/psalm": "^4.10",
27+
"phpunit/phpunit": "^9.5"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"SendGridValidation\\": "src"
32+
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"SendGridValidation\\Tests\\": "tests"
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)