Marcus2000 Posted March 2, 2011 Share Posted March 2, 2011 Hi people, I am a complete newbe to php but can some one please help us out a little with a bit of code? Basically i have a contact form, when the user submits the form it gets processed by my php page and the data sent of to my email address. The thing is I have wrote most of the code for this and i think it should work, however i want to add a bit of code that re-directs the user to a "thank you" page after they submit the form. I hope that makes sense, please check out the code below and please let me know what and where to put the re-direct code, please also let me know if the code i have written so far is correct. my code <?php if(isset($_POST['submit'])) { $to = "me@my_email_address.com"; $subject = "Contact Form"; $name = $_POST['name']; $comp_name = $_POST['company_name']; $email = $_POST['email']; $phone = $_POST['contact_number']; $location = $_POST['location']; $message = $_POST['message']; $body = "From: $name\n E-Mail: $email\n Company Name: $comp_name\n Contact Number: $phone:\n Location: $location:\n Message:\n $message"; mail($to, $subject, $body); } ?> Cheers people, hope some one can help. Quote Link to comment Share on other sites More sharing options...
gastroll Posted March 2, 2011 Share Posted March 2, 2011 I am looking for the same thing. Someone told me I should insert if (mail($to, $...)) header("Location:/thankyou.html"); else header("Location:/error.html"); at the end but it did not work out for me. Quote Link to comment Share on other sites More sharing options...
Marcus2000 Posted March 2, 2011 Author Share Posted March 2, 2011 Thanks for trying mate, but that dont work for me either dude. Does anyone have any sugestions? Cheers. Quote Link to comment Share on other sites More sharing options...
Twistedweb123 Posted March 2, 2011 Share Posted March 2, 2011 Try this out <?php if(isset($_POST['submit'])) { $to = "me@my_email_address.com"; $subject = "Contact Form"; $name = $_POST['name']; $comp_name = $_POST['company_name']; $email = $_POST['email']; $phone = $_POST['contact_number']; $location = $_POST['location']; $message = $_POST['message']; $body = "From: $name\n E-Mail: $email\n Company Name: $comp_name\n Contact Number: $phone:\n Location: $location:\n Message:\n $message"; $sendit= @mail($to, $subject, $body); if($sendit){ header('Location: yourlocation'); }else{ echo "Email failed to send";} } ?> the header can be defined in numerous ways. If you want it to go to a new site, write header('Location: http://www.thesite.com/'); if you want it to go to a page in the same directory as yours, do something like this header('Location: thankyou.php'); 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.