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: Added support for identifying and working with Gmail addresses using the "plus trick" to create unique addresses
Date: 6 months 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;
}

For more information send a message to info at phpclasses dot org.