Help - Search - Members - Calendar
Full Version: How Can I Verify An Email Address That Is Entered On My Web Form?
Zymic Webmaster Forums > Web Design & Development > General Web Design Discussion
craig2u
Sometime my visitors mistype their email address. I want to verify it so their message is not delivered until the email field is ok. Something like checking for @ character, etc.
Stryker
You can use another error output method but that generally works for me.

CODE
$errors = array();
$regex = "/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+.[a-z]{2,}$/i";
if(!preg_match($regex, $email_field))
{
  $errors[] = "E-mail is not in correct format!<br />";
}
Ed
PHP5 comes with a fantastic little filter library:

CODE
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
    // Email format is correct
}


If you're not on Zymic hosting you can extend the check to start a smtp session with the domain's mail exchange servers and check the email address actually exists. This method isn't full proof if someone sets their MX records to point to a mailserver which has been setup as a relay.

Email verification is the best method to ensure the mailbox actually exists.
craig2u
QUOTE(Ed @ Oct 1 2009, 11:10 AM) *
PHP5 comes with a fantastic little filter library:

CODE
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
    // Email format is correct
}


If you're not on Zymic hosting you can extend the check to start a smtp session with the domain's mail exchange servers and check the email address actually exists. This method isn't full proof if someone sets their MX records to point to a mailserver which has been setup as a relay.

Email verification is the best method to ensure the mailbox actually exists.

To my surprise, my free hosting service does not have PHP5 , or even worst, any version of PHP. So my only solution is to use a remotely hosted form service, like http://www.123contactform.com or http://www.kontactr.com
Ed
QUOTE(craig2u @ Oct 2 2009, 10:35 AM) *
To my surprise, my free hosting service does not have PHP5 , or even worst, any version of PHP. So my only solution is to use a remotely hosted form service, like http://www.123contactform.com or http://www.kontactr.com


Zymic's free hosting offers php5; However we don't provide outgoing connections so SMTP checks can't be performed, filter exists however and mail() can be enabled for a one off $10 charge.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.