Re: Checking email
| From: | Todd Williamsen | Date: | Tue, 12 Feb 2002 19:25:03 +0000 |
| Subject: | Re: Checking email | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-12036@lists.php.net to get a copy of this message | ||
Here is a script that actually connects to their mail server to see if its
valid
<?
// Set the form error check to false
$form_errors = array();
//E-Mail address verifications
// Make Email a required field
$Email = trim($Email);
if ($Email == "") {
$form_errors["required_Email"] = true;
}
elseif
(!eregi("^([a-zA-Z0-9._-])+@([a-zA-Z0-9._-])+\.([a-zA-Z0-9._-])([a-zA-Z0-9._
-])+", $Email)) {
$form_errors["Email_badformat"] = true;
}
// Attempt to resolve the MX host
else {
list($user, $domain) = split("@", $Email, 2);
if (! checkdnsrr($domain, "MX")) {
$form_errors["Email_badhost"] = true;
}
}
// Check if there are any errors
if (count($form_errors)) {
// If the user left the e-mail field blank
if ($form_errors["required_Email"]) {
echo("<font color=\"#ff0000\"><b>Your E-mail Address is
required.</b></font>");
}
// If the format of the e-mail address is incorrect
elseif ($form_errors["Email_badformat"]) {
echo("<font color=\"#ff0000\"><b>Please enter a valid e-mail
address.</b></font>");
}
// If the mail server of the address the user provided could not be
contacted
elseif ($form_errors["Email_badhost"]) {
echo("<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>");
}
}
?>
"Marko Mihalec" <marko.mihalec@ck.tel.hr> wrote in message
news:20020209093400.55441.qmail@pb1.pair.com...
> function isEmailInvalid($val)
> {
> // regex for email validation
> $pattern =
> "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
>
> // match?
> if(preg_match($pattern, $val))
> {
> return 0;
> }
> else
> {
> return 1;
> }
> }
>
>
>
>
>
>