PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   PHP Email Validation Quality   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: PHP Email Validation Quality
Validate email address and compute quality score
Author: By
Last change: simple housekeeping
Date: 8 years ago
Size: 2,623 bytes
 

Contents

Class file image Download
<?php

//include the class
include('mailboxlayer.class.php');

//instantiate the class
$mbox = new mailBoxLayer();

//email address to check
$email = 'test@domain.com';

if(
$mbox->verifyMail($email) === false ){
   
//an error occured
   
   
echo 'The request returned an error -> ['.$mbox->errorCode.'] '.$mbox->errorText;
   
}else{
   
    if( empty(
$mbox->response->format_valid ) ){
       
        echo
'Not a properly formatted e-mail address<br>';
       
    }else{
       
        echo
'Properly formatted e-mail address<br>';
       
    }
   
    if( !empty(
$mbox->response->did_you_mean) ){
       
        echo
'Possibly the correct e-mail address is: '.$mbox->response->did_you_mean.'<br>';
       
    }
   
    if( empty(
$mbox->response->mx_found) ){
       
        if(
$mbox->response->mx_found === null ){
           
            echo
'mx record not checked<br>';
           
        }else{
           
            echo
'mx record not found<br>';
           
        }
       
    }else{
       
        echo
'mx record found<br>';
       
    }
   
    if( empty(
$mbox->response->smtp_check) ){
       
        if(
$mbox->response->smtp_check === null ){
           
            echo
'smtp server not checked<br>';
           
        }else{
           
            echo
'smtp server not found<br>';
           
        }
       
    }else{
       
        echo
'smtp server found';
       
    }
   
    echo
'score = '.$mbox->response->score.'<br>';
   
$quality = $mbox->response->score * 100;
   
   
//suggested transactional quality
   
echo 'Quality is ';
    if(
$quality < 33 ){
       
        echo
'bad<br>';
       
    }elseif(
$quality < 65 ){
       
        echo
'moderate<br>';
       
    }else{
       
        echo
'good<br>';
       
    }
   
}

var_dump($mbox->response);
/*
a validation request will return the following object properties

email - email address to verify
did_you_mean - suggested correct email, if any
user - user name part of email
domain - domain part of email
format_valid - true/false, true if valid email format
mx_found - true/false/null - true if mx record found, null if not checked
smtp_check - true/false/null - true if smtp server found, null if not checked
catch_all - true/false - true if catch all email
role - true/false - true if role specific email
disposable = true/false - true if disposable email
free = true/false - true if free service provider
score = quality score between 0 and 1
*/

?>