rayhughes / sendgrid-validation
A PHP library to validate email addresses using the Twilio SendGrid Email Validation API.
Installs: 1 126
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: 7.4.5.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.10
README
A PHP library to validate email addresses using the Twilio SendGrid Email Validation API.
Prerequisites
- Twilio SendGrid Email Validation API Key
- PHP 7.4 or greater
- Composer
Installation
composer require rayhughes/sendgrid-validation
Usage
Basic
EmailValidation()
initialized with default thresholds.
use SendGridValidation\EmailValidation; use SendGridValidation\Repository\SendGridApiRepository; $validation = new EmailValidation(new SendGridApiRepository('api-key')); $emailValid = $validation->validate('email@example.com')); echo $emailValid->isValid; // true echo $emailValid->isValidRisk; // true echo $emailValid->isValidScore; // true echo $emailValid->isDisposable; // false echo $emailValid->hasSuggestion; //false echo $emailValid->suggestion; // null
EmailValidation()->validate()
returns an instance of EmailValidationDto()
EmailValidationDto()
$isValid
- Calculatedtrue
if validation result meets specified thresholds.$isValidRisk
- Calculatedtrue
specified risk criteria$isValidScore
- Calculatedtrue
if within minimum score threshold.$isDisposable
- Calculatedtrue
if an email is considered to be disposable.$hasSuggestion
- Calculatedtrue
if a suggestion is available.$suggestion
- Calculated email suggestion if available.
class EmailValidationDto { public bool $isValid = false; public bool $isValidRisk = false; public bool $isValidScore = false; public bool $isDisposable = false; public bool $hasSuggestion = false; public ?string $suggestion = null; }
Advanced
EmailValidation()
can be initialized with optional parameters to validate against developer specified thresholds.
$allowRisky
- Whentrue
, considers risky emailsvalid
if other conditions are met.$allowDisposable
- Whentrue
, considers disposable emailsvalid
if other conditions are met.$checkValidScore
- Whentrue
, checks SendGridvalid
emails against the minimum score threshold.$minSCore
- Default0.30
. considers emailsinvalid
if the minimum score threshold is not met.
use SendGridValidation\EmailValidation; use SendGridValidation\Repository\SendGridApiRepository; $validation = new EmailValidation( new SendGridApiRepository($apiKey), true, // bool $allowRisky = true, true, // bool $allowDisposable = true, true, // bool $checkValidScore = false, EmailValidation::MIN_SCORE // float $minScore = self::MIN_SCORE (0.30) ); $emailValid = $validation->validate($email);