PHP valid e-mail submission problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jovankau
Forum Newbie
Posts: 10
Joined: Tue Feb 26, 2008 12:25 am

PHP valid e-mail submission problem

Post by jovankau »

Hi everyone,

Hoping to get some help with some PHP code. There is HTML code embedded too.

Okay, so what I have is a standard web form where people enter their contact info if they want further information.

Have got the rest of the form validating and working fine, except for the e-mail part.

The validation works okay, if someone submits something incorrectly i.e no "@", error message to user is okay.

Issue is when user submits a vaild email address i.e. meets all the conditions outlined, the HTML code is generated as well as the "congratulations your submission has gone through" message.

Do you have any ideas of what I need to change?

Thanks so much,
Jo

Here is my code:

Code: Select all

 
 
if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{
 
if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email']))
{$errors[] = "Email ERROR";}
 
$_REQUEST['email'] = trim($_REQUEST['email']);
 
if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email ERROR";}
 
else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1]))
 
{$errors[] = "Email ERROR";}
 
else{if(substr_count($exploded_email[1],".") == 0){
$errors[] = "Email ERROR";}
 
else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain))
 
{$errors[] = "Email ERROR";}
 
else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email ERROR"; break;}}}}}
}
 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Code: Select all

 <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>NAME - ERROR</title><!-- CSS --><link href="_css/global.css" rel="stylesheet" type="text/css" media="all" /><style type="text/css"></style></head><body> <div id="goldheader"></div> <div class="wrapper"><div><center><div id="logo"> <a href="index.html" title="logo"><img src="_images/logo.gif" alt="Paycheck Investigators" border="0"></a></div><br><br><font size=20px><b><center>Error</center></b></font size><br></body> 

Code: Select all

 
 
}
 
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: PHP valid e-mail submission problem

Post by Jade »

Is it giving you an error message?
Post Reply