|
<?
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;
}
?> |