PHP Classes

File: test_email_validation.php

Recommend this page to a friend!
  Classes of Manuel Lemos   PHP Email validation   test_email_validation.php   Download  
File: test_email_validation.php
Role: Example script
Content type: text/plain
Description: E-mail validation test page script
Class: PHP Email validation
Determine if a given e-mail address is valid.
Author: By
Last change: Removed the example code that used an external library that emulated the
GetMXRR because PHP already implements this function.
Date: 5 months ago
Size: 3,646 bytes
 

Contents

Class file image Download
<?php
/*
 * test_email_validation.html
 *
 * @(#) $Header: /opt2/ena/metal/emailvalidation/test_email_validation.php,v 1.14 2024/02/07 12:19:09 mlemos Exp $
 *
 */

?><html>
<head>
<title>Test for Manuel Lemos's PHP E-mail validation class</title>
</head>
<body>
<h1 align="center">Test for Manuel Lemos's PHP E-mail validation class</h1>
<hr>
<?php
   
require("email_validation.php");

   
$validator=new email_validation_class;

   
/* how many seconds to wait before each attempt to connect to the
       destination e-mail server */
   
$validator->timeout=10;

   
/* how many seconds to wait for data exchanged with the server.
       set to a non zero value if the data timeout will be different
         than the connection timeout. */
   
$validator->data_timeout=0;

   
/* user part of the e-mail address of the sending user
       (info@phpclasses.org in this example) */
   
$validator->localuser="info";

   
/* domain part of the e-mail address of the sending user */
   
$validator->localhost="phpclasses.org";

   
/* Set to 1 if you want to output of the dialog with the
       destination mail server */
   
$validator->debug=1;

   
/* Set to 1 if you want the debug output to be formatted to be
    displayed properly in a HTML page. */
   
$validator->html_debug=1;


   
/* When it is not possible to resolve the e-mail address of
       destination server (MX record) eventually because the domain is
       invalid, this class tries to resolve the domain address (A
       record). If it fails, usually the resolver library assumes that
       could be because the specified domain is just the subdomain
       part. So, it appends the local default domain and tries to
       resolve the resulting domain. It may happen that the local DNS
       has an * for the A record, so any sub-domain is resolved to some
       local IP address. This prevents the class from figuring if the
       specified e-mail address domain is valid. To avoid this problem,
       just specify in this variable the local address that the
       resolver library would return with gethostbyname() function for
       invalid global domains that would be confused with valid local
       domains. Here it can be either the domain name or its IP address. */
   
$validator->exclude_address="";
   
$validator->invalid_email_domains_file = 'invalidemaildomains.csv';
   
$validator->invalid_email_servers_file = 'invalidemailservers.csv';
   
$validator->email_domains_white_list_file = 'emaildomainswhitelist.csv';

    if(IsSet(
$_GET["email"]))
       
$email=$_GET["email"];
    if(IsSet(
$email)
    &&
strcmp($email,""))
    {
        if(
strlen($error = $validator->ValidateAddress($email, $valid)))
        {
            echo
"<h2 align=\"center\">Error: ".HtmlSpecialChars($error)."</h2>\n";
        }
        elseif(!
$valid)
        {
            echo
"<h2 align=\"center\"><tt>$email</tt> is not a valid deliverable e-mail box address.</h2>\n";
            if(
count($validator->suggestions))
            {
               
$suggestion = $validator->suggestions[0];
               
$link = '?email='.UrlEncode($suggestion);
                echo
"<H2 align=\"center\">Did you mean <a href=\"".HtmlSpecialChars($link)."\"><tt>".HtmlSpecialChars($suggestion)."</tt></a>?</H2>\n";
            }
        }
        elseif((
$result=$validator->ValidateEmailBox($email))<0)
            echo
"<h2 align=\"center\">It was not possible to determine if <tt>$email</tt> is a valid deliverable e-mail box address.</h2>\n";
        else
            echo
"<h2 align=\"center\"><tt>$email</tt> is ".($result ? "" : "not ")."a valid deliverable e-mail box address.</h2>\n";
    }
    else
    {
       
$email = 'your@test.email.here';
       
$link = '?email='.$email;
        echo
"<h2 align=\"center\">Access this page using passing the email to validate here: <a href=\"".HtmlSpecialChars($link)."\"><tt>".$email."</tt></a></h2>\n";
    }
?>
<hr>
</body>
</html>