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: 23 days ago
Size: 3,646 bytes


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

<title>Test for Manuel Lemos's PHP E-mail validation class</title>
<h1 align="center">Test for Manuel Lemos's PHP E-mail validation class</h1>

$validator=new email_validation_class;

/* how many seconds to wait before each attempt to connect to the
       destination e-mail server */

/* 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. */

/* user part of the e-mail address of the sending user
       ( in this example) */

/* domain part of the e-mail address of the sending user */

/* Set to 1 if you want to output of the dialog with the
       destination mail server */

/* Set to 1 if you want the debug output to be formatted to be
    displayed properly in a HTML page. */

/* 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->invalid_email_domains_file = 'invalidemaildomains.csv';
$validator->invalid_email_servers_file = 'invalidemailservers.csv';
$validator->email_domains_white_list_file = 'emaildomainswhitelist.csv';

strlen($error = $validator->ValidateAddress($email, $valid)))
"<h2 align=\"center\">Error: ".HtmlSpecialChars($error)."</h2>\n";
"<h2 align=\"center\"><tt>$email</tt> is not a valid deliverable e-mail box address.</h2>\n";
$suggestion = $validator->suggestions[0];
$link = '?email='.UrlEncode($suggestion);
"<H2 align=\"center\">Did you mean <a href=\"".HtmlSpecialChars($link)."\"><tt>".HtmlSpecialChars($suggestion)."</tt></a>?</H2>\n";
"<h2 align=\"center\">It was not possible to determine if <tt>$email</tt> is a valid deliverable e-mail box address.</h2>\n";
"<h2 align=\"center\"><tt>$email</tt> is ".($result ? "" : "not ")."a valid deliverable e-mail box address.</h2>\n";
$email = '';
$link = '?email='.$email;
"<h2 align=\"center\">Access this page using passing the email to validate here: <a href=\"".HtmlSpecialChars($link)."\"><tt>".$email."</tt></a></h2>\n";