It can check a given e-mail address by verifying if it matches a regular expression with a pattern of valid e-mail addresses.
The class can also check the existence e-mail address domain by opening a connection to a host with the e-mail domain name.
index.php
<?php
/*
EValid, Email Address Validator
Author: Roberto Aleman
General Public License (GPL)
How to Work?
1.- check length of email address max is 320 characters where:
64 characters max for the user of email address
1 character max for the @
255 characters max for the host name
2.- apply regular expressions to valid email addres string
3.- check if exist host to send messages to email address
*/
require_once("eavalidator.php");
if(isset($_POST['submit']))
{
$newemail = new email_validator();
$newemail->check_email($_POST[Email]);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form action='index.php' method='post' >
<p>Your Email:<input name='Email' type='text' size='50' id="submit" /></p>
<input name='submit' type='submit' /></form>
</body>
</html>
eavalidator.php
<?php
class email_validator
{
function check_email($EMAIL)
{
$email = trim(strtolower($EMAIL));
if (strlen($email) <= 320 AND strlen($email)>0)
{
echo "valid length entry, : ".$EMAIL."<br/>";
echo "it has ".strlen($email)." characters in length</br>";
$model = '/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])'.'(([a-z0-9-])*([a-z0-9]))+'.'(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i';
if ( preg_match ($model, $email) == TRUE)
{
list($user, $domain) = explode("@", $email);
$id = @fopen("http://".$domain,"r");
if ($id == true )
{
echo "Valid Email , Send Message to ".$email;
//function mail() here
fclose($id);
}
else
{
echo "Not valid Host, Not Send Message to ".$email;
}
}
else
{
echo "Not valid, Not Send Message to ".$email." characters not accepted or they are missing characters";
}
}
else
{
if (strlen($lower) == NULL)
{
echo "no valid entry, because is null: ".$email."<br/>";
echo "it has ".strlen($lower)." characters in length</br>";
}
else
{
echo "no valid entry, because is too much long: ".$email;
echo "it has ".strlen($lower)." characters in length characters</br>";
}
}
}
}
?>