PHP Classes

File: examples/fullValidation.php

Recommend this page to a friend!
  Classes of John Conde   PHP Email Validation Library Pro   examples/fullValidation.php   Download  
File: examples/fullValidation.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Email Validation Library Pro
Validate email addresses using multiple rules
Author: By
Last change: Update of examples/fullValidation.php
Date: 1 year ago
Size: 1,392 bytes
 

Contents

Class file image Download
<?php

namespace EmailValidator;

require(
'../vendor/autoload.php');

$customDisposableEmailList = [
   
'example.com',
];

$bannedDomainList = [
   
'domain.com',
];

$customFreeEmailList = [
   
'example2.com',
];

$testEmailAddresses = [
   
'test@domain.com',
   
'test@johnconde.net',
   
'test@gmail.com',
   
'test@hotmail.com',
   
'test@outlook.com',
   
'test@yahoo.com',
   
'test@domain.com',
   
'test@mxfuel.com',
   
'test@example.com',
   
'test@example2.com',
   
'test@nobugmail.com',
   
'test@cellurl.com',
   
'test@10minutemail.com',
   
'test+example@gmail.com',
];

$config = [
   
'checkMxRecords' => true,
   
'checkBannedListedEmail' => true,
   
'checkDisposableEmail' => true,
   
'checkFreeEmail' => true,
   
'bannedList' => $bannedDomainList,
   
'disposableList' => $customDisposableEmailList,
   
'freeList' => $customFreeEmailList,
];
$emailValidator = new EmailValidator($config);

foreach (
$testEmailAddresses as $emailAddress) {
   
$emailIsValid = $emailValidator->validate($emailAddress);
    echo (
$emailIsValid) ? 'Email is valid' : $emailValidator->getErrorReason();
    if (
$emailValidator->isGmailWithPlusChar()) {
       
printf(
           
' (%s is a Gmail account and contains a plus character. Sanitized address: %s)',
           
$emailAddress,
           
$emailValidator->getGmailAddressWithoutPlus()
        );
    }
    echo
PHP_EOL;
}