A PHP library to validate email addresses using the Twilio SendGrid Email Validation API.
- Twilio SendGrid Email Validation API Key
- PHP 7.4 or greater
- Composer
composer require rayhughes/sendgrid-validation
EmailValidation()
initialized with default thresholds.
use SendGridValidation\EmailValidation;
use SendGridValidation\Repository\SendGridApiRepository;
$validation = new EmailValidation(new SendGridApiRepository('api-key'));
$emailValid = $validation->validate('[email protected]'));
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()
$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;
}
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);