Ricklord Posted August 17, 2006 Share Posted August 17, 2006 Hi Guys, I been trying to use some tuturials to add a email validator to my current email script. this is what ive come up with so far. [code]<?php header("Location: http://www.creativecogs.co.uk/web_design/thankyou.html");if(isset($_POST['submit'])) { $to = "rick@creativecogs.co.uk"; $subject = "Web Design Online enquiry"; $name_field = $_POST['name']; $email_field = $_POST['email'];$telephone_field = $_POST['telephone']; $message = $_POST['message']; $header = "From: {$name}<{$email_field}>";function checkemail($email_field){ return preg_match("/^[^\s()<>@,;:\"\/\[\]?=]+@\w[\w-]*(\.\w[\w-]*)*\.[a-z]{2,}$/i",$email_field); } if((!$email_field) OR (!checkemail($email_field))){ echo ' - You did not enter a valid e-mail address.'; exit; } foreach($_POST['check'] as $value) { $check_msg .= "Checked: $value\n"; } $body = "From: $name_field\n E-Mail: $email_field\n Telephone: $telephone_field\n $check_msg Option: $option\n Message: $message"; echo "Data has been submitted to $to!"; mail($to, $subject, $body, $header); } else { echo "failed please try again"; } ?> [/code]If i take the header out the checker will follow the echo command when an email address is invalid which is what i want but i also want to forward to my thankyou page if the email is valid. I'm not a php coder i just learn as i go, take tuturials learn what they do and then change them to fit my needs. If some one could point out how i can correct this i would be greatful. Is there another comand to use which i can put at the end of the script to forward onto my thankyou page? from my understanding the header command has got to be at the top of the script and will be executed first so teh user would get redirected before the check is actually done in my above example. Any help will be great CheersRick Quote Link to comment Share on other sites More sharing options...
Ricklord Posted August 17, 2006 Author Share Posted August 17, 2006 Sorry forgot to add this. instead of the echo command can i use a function/command which will forward to an error page rather than printed text. CheersRick Quote Link to comment Share on other sites More sharing options...
Ricklord Posted August 19, 2006 Author Share Posted August 19, 2006 anyone got any suggestions on this one?cheersRick Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 19, 2006 Share Posted August 19, 2006 Rick - the header() function needs to appear before any output to the browser, not before any code.Given that it's redundant to echo a success message and then move to a thank you page (which can just as well say 'Your message has been sent'), just rearrange parts of your code thus:[code]...$body = "From: $name_field\n E-Mail: $email_field\n Telephone: $telephone_field\n $check_msg Option: $option\n Message: $message"; mail($to, $subject, $body, $header); header("Location: http://www.creativecogs.co.uk/web_design/thankyou.html");exit();// to be sure[/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.