PHP Classes

File: validate.php

Recommend this page to a friend!
  Classes of Dave Cobbe  >  JsonEmail  >  validate.php  >  Download  
File: validate.php
Role: Example script
Content type: text/plain
Description: Example file using JSON wrapper around an email validation class
Class: JsonEmail
Get the results of email validation in JSON format
Author: By
Last change:
Date: 3 years ago
Size: 2,350 bytes
 

Contents

Class file image Download
<?php
header
( 'Content-Type:application/json;charset=utf-8' );
include_once(
'JsonReturn.class.php' );
$result = JsonReturn::onVoid();

if( !isset(
$_GET["email"]) ) {
   
$p_emailAddress = "void";
} else {
   
$p_emailAddress = urldecode( filter_input( INPUT_GET, "email", FILTER_SANITIZE_EMAIL ) );
}

if(
filter_var( $p_emailAddress, FILTER_VALIDATE_EMAIL ) ) {

    require_once(
'emailValidation.class.php' );
   
   
$validator = new email_validation_class;
   
$validator->timeout = 10;
   
$validator->data_timeout = 0;
   
$validator->localuser = "system.admin";
   
$validator->localhost = "victoriahome.ch";
   
$validator->debug = 0;
   
$validator->html_debug = 0;
   
$validator->exclude_address = "";
   
$validator->invalid_email_domains_file = 'resources/invalidemaildomains.csv';
   
$validator->invalid_email_servers_file = 'resources/invalidemailservers.csv';
   
$validator->email_domains_white_list_file = 'resources/emaildomainswhitelist.csv';
   
    if(
strlen( $errorCode = $validator->ValidateAddress( $p_emailAddress, $errorReturn ) ) ) {
       
$result = JsonReturn::onError( "Error: " . HtmlSpecialChars( $errorReturn ) );
    } else {
        if( !
$errorReturn ) {
            if(
count( $validator->suggestions ) ) {
               
$suggestion = $validator->suggestions[0];
               
$result = JsonReturn::onError( "Possible typo: did you mean " . HtmlSpecialChars( $suggestion ) . "?" );
            } else {
               
$result = JsonReturn::onError( HtmlSpecialChars( $p_emailAddress ) . " is not a valid deliverable e-mail address." );
            }
        } else {
            if( (
$deliverable = $validator->ValidateEmailBox( $p_emailAddress ) ) < 0 ) {
               
$result = JsonReturn::onError( "Warning: is was not possible to determine if " . HtmlSpecialChars( $p_emailAddress ) . " is a valid deliverable e-mail address." );
            } else {
                if( !
$deliverable ) {
                   
$result = JsonReturn::onError( "Error: " . HtmlSpecialChars( $p_emailAddress ) . " is not a deliverable e-mail address." );
                } else {
                   
$result = JsonReturn::onValue( $validator );
                }
            }
        }
    }

} else {
   
$result = JsonReturn::onError( "Syntax error found in email address." );
}

echo
$result->toString();
?>

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