Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

 
E-mail Validation-Check format and MX records

This script not only checks the validity of the format of the e-mail address, but it attempts to connect to the mail server of the submitted e-mail address as well. Don't settle for a database full of fake e-mail addresses.

Script Name : SafValidatemail() Version : 1.2
Developer : Safras Ahamed Date 03/13/2003
Used Functions : eregi(), split(), checkdnsrr(), list(), count(), trim()
 

<?
function SafValidatemail($MYEMAIL){
    
$myerror = "";
    
$form_errors = array();    // Set the form error check to false
    
$MYEMAIL = trim($MYEMAIL); // Make Email a required field
    
if ($MYEMAIL == "") {
        
$form_errors["required_Email"] = true;
        }elseif (!
eregi("^([a-zA-Z0-9._-])+@([a-zA-Z0-9._-])+\.([a-zA-Z0-9._-])([a-zA-Z0-9._-])+", $MYEMAIL)) {
            
$form_errors["Email_badformat"] = true;
    }else {
        list(
$user, $domain) = split("@", $MYEMAIL, 2); // Attempt to resolve the MX host
        
if (! checkdnsrr($domain, "MX")) {
            
$form_errors["Email_badhost"] = true;
        }
    }

    if (
count($form_errors)) {    // Check if there are any errors
    
        
if ($form_errors["required_Email"]) { // If the user left the e-mail field blank
            
$myerror="<font color=\"#ff0000\"><b>Your E-mail Address is required.</b></font>";
    
        }elseif (
$form_errors["Email_badformat"]) { // If the format of the e-mail address is incorrect
            
$myerror.="<font color=\"#ff0000\"><b>Please enter a valid e-mail address.</b></font>";
    
        }elseif (
$form_errors["Email_badhost"]) { // If the mail server of the address the user provided could not be contacted
            
$myerror.="<font color=\"#ff0000\"><b>Your E-mail address did not resolve to a working e-mail server.<br> Please enter a valid e-mail address.</b></font>";
        }
        print
$myerror;
    }else{    
        
$myerror="";
        print
$myerror;
    }
}
// end of function

//////////////////////////This is how it will work /////////////////////

$MyGoodness = SafValidatemail($MYEMAIL);
if (
$MyGoodness=""){
print
"Email is Good";
}else{
//Email is not working or error
print $MyGoodness;
}    
?>

 
Web Master : Safras Ahamed, Email : safras@ArabChat.Org
Copyright 2003 ArabChat Network