Name: validateemail.php
Description: Validates an email against MX records
Usage:
include validateemail.php
Pass an email to validateEmail();
Example:
if (validateEmail("somename@domain.com")) {
//code block
}
Guest_Jordan_*
if (validateEmail("somename@domain.com")) {
//code block
}
|
|
|
Guest_Jordan_*
Guest_moguai_*
Guest_lambert1969_*
Guest_yosutanto_*
/**
*@param $Email is the email address you wish to validate
*@return $result[0] will either be true or false. True
* meaning the email is valid - False meaning the email
* meaning the email is invalid.
*@return $result[1] is a brief message explaining the result.
*/
function VerifyEmail ($Email)
{
$result = array();
#Use a regular expression to make sure the $Email string is in proper format
#<username>@<domain>.<suffix> || <username>@<subnet>.<domain>.<suffix>
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $Email)) {
$result[0] = false;
$result[1] = "$email is not properly formatted.";
return $result;
}
list ($Username, $Domain) = split ("@", $Email);
#Verify the MX record.
if (getmxrr($Domain, $MXHost)) {
$result[0] = true;
$result[1] = "$email appears to be valid.";
return $result;
} else {
#Establish a connection to the server.
if (@fsockopen($Domain, 25, $errno, $errstr, 30)) {
$result[0] = true;
$result[1] = "$email appears to be valid.";
return $result;
} else {
$result[0] = false;
$result[1] = "Cannot connect to the server.";
return $result;
}
}
} //End VerifyEmail
$result = VerifyEmail ($Email);
if($result[0]) {
//email is valid
}