PHP code example of phporbit / php-email-validator

1. Go to this page and download the library: Download phporbit/php-email-validator 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/ */

    

phporbit / php-email-validator example snippets


use PHPOrbit\EmailValidator\EmailValidator;
use PHPOrbit\EmailValidator\Fetcher;

// Load blocklist and allowlist from the package
$blocklist = Fetcher::loadBlocklist();
$allowlist = Fetcher::loadAllowlist();

// Initialize the validator
$validator = new EmailValidator($blocklist, $allowlist);

$email = "[email protected]";

// Perform validations
if (!$validator->isValidFormat($email)) {
    echo "Invalid email format.";
} elseif ($validator->isDisposable($email)) {
    echo "Disposable email detected.";
} elseif (!$validator->hasValidMX($email)) {
    echo "Invalid MX record.";
} else {
    echo "Email is valid.";
}

use PHPOrbit\EmailValidator\EmailValidator;
use PHPOrbit\EmailValidator\Fetcher;

$blocklist = Fetcher::loadBlocklist();
$allowlist = Fetcher::loadAllowlist();
$validator = new EmailValidator($blocklist, $allowlist);

$email = $_POST['email'] ?? '';

if (!$validator->isValidFormat($email)) {
    die("Error: Invalid email format.");
}

if ($validator->isDisposable($email)) {
    die("Error: Disposable email addresses are not allowed.");
}

if (!$validator->hasValidMX($email)) {
    die("Error: Email domain does not have a valid MX record.");
}

echo "Success: Email is valid and ready for registration.";
bash
composer