drfill Posted August 13, 2006 Share Posted August 13, 2006 HelloI am somewhat of a newbie when it comes to php, so I appreciate this question is probably very elementary. I currently have a form [code]$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;$name = $_POST['name'] ;$from = $_POST['from'] ;$location = $_POST['location'] ;$interested = $_POST['interested'] ;$budget = $_POST['budget'] ;$distance = $_POST['distance'] ;$progress = $_POST['progress'] ;$comments = $_POST['comments'] ;$http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['from'])) { header( "Location: $formurl" ); exit ;}if (empty($name) || empty($from)) { header( "Location: $errorurl" ); exit ;}if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $from ) ) { header( "Location: $errorurl" ); exit ;}if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments );}$messageproper = "Enquiry from:\n" .[/code]etc that is a regular run of the mill 'send a email from form' scriptHowever, I get a lot of people entering wrong email addresses, e.g. using commas, not putting a suffix on, etc - so I'm wanting to be able to validate that the email address entered is in the correct format.So far I've tried several bits of code out, e.g.[code]function valid_email($from){ // check an email address is possibly valid if (ereg('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$', $from)) return true; else header( "Location: $errorurl" ); exit ; }[/code]but they all return one error or another. Unfortunately given my very basic knowledge of how php works I can't integrate the latter code with the above code. If anyone can give me any pointers on how to do this it would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
willpower Posted August 14, 2006 Share Posted August 14, 2006 post your complete code with the integration of the validation....it may just be in the wrong place. Then we can solve your issue Quote Link to comment Share on other sites More sharing options...
drfill Posted August 14, 2006 Author Share Posted August 14, 2006 ok here it is[code]<?$mailto = email@address.com;$subject = "Feedback" ;$formurl = "index.html" ;$errorurl = "application-error.html" ;$thankyouurl = "_application.html" ;$uself = 0; $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;$name = $_POST['name'] ;$from = $_POST['from'] ;$location = $_POST['location'] ;$http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['from'])) { header( "Location: $formurl" ); exit ;}if (empty($name) || empty($from)) { header( "Location: $errorurl" ); exit ;}function valid_email($from){ // check an email address is possibly valid if (ereg('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$', $from)) return true; else header( "Location: $errorurl" ); exit ; }if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $from ) ) { header( "Location: $errorurl" ); exit ;}if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments );}$messageproper = "Enquiry from:\n" . "$http_referrer\n" . "------------------------------------------------------------\n" . "Name: $name\n" . "Email: $from\n" . "Location: $location\n" . "Interested in: $interested\n" . "\n\n------------------------------------------------------------\n" ;mail($mailto, $subject, $messageproper, "From: \"$from\" <$from>" . $headersep . "Return-Path: \"$name\" <$from>" . $headersep . "Reply-To: \"$from\" <$from>" . $headersep . "X-Mailer: chfeedback.php 2.07" );header( "Location: $thankyouurl" );exit ;?>[/code]as you can see, the code is just sitting there. I've tried it in a few different places, but nought works Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted August 14, 2006 Share Posted August 14, 2006 Since the email verification is a function you have to call it. Functions don't do anything unless you say hey, I need you to work! :)[code]$mailto = email@address.com;$subject = "Feedback" ;$formurl = "index.html" ;$errorurl = "application-error.html" ;$thankyouurl = "_application.html" ;$uself = 0; $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;$name = $_POST['name'] ;$from = $_POST['from'] ;$location = $_POST['location'] ;$http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['from'])) { header( "Location: $formurl" ); exit ;}if (empty($name) || empty($from)) { header( "Location: $errorurl" ); exit ;}function valid_email($from){ // check an email address is possibly valid if (ereg('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$', $from)) return true; else header( "Location: $errorurl" ); exit ; }$email_err = valid_email($from);if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $from ) ) { header( "Location: $errorurl" ); exit ;}if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments );}$messageproper = "Enquiry from:\n" . "$http_referrer\n" . "------------------------------------------------------------\n" . "Name: $name\n" . "Email: $from\n" . "Location: $location\n" . "Interested in: $interested\n" . "\n\n------------------------------------------------------------\n" ;mail($mailto, $subject, $messageproper, "From: \"$from\" <$from>" . $headersep . "Return-Path: \"$name\" <$from>" . $headersep . "Reply-To: \"$from\" <$from>" . $headersep . "X-Mailer: chfeedback.php 2.07" );header( "Location: $thankyouurl" );exit ;[/code] Quote Link to comment Share on other sites More sharing options...
drfill Posted August 14, 2006 Author Share Posted August 14, 2006 sorry, I should clarify and say that the form works perfectly until I add the extra code into it, and thats when things fall apart. Quote Link to comment Share on other sites More sharing options...
DylanBlitz Posted August 14, 2006 Share Posted August 14, 2006 ok, what does it do when you add the extra code? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.