PHP code example of rayhughes / sendgrid-validation

1. Go to this page and download the library: Download rayhughes/sendgrid-validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rayhughes / sendgrid-validation example snippets


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

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;
}

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);