ruralscot Posted April 11, 2010 Share Posted April 11, 2010 Hopefully someone can help prior to scratching my head through the my brain!!! I have a code all sorted for a very quick form, all is working well and I am receiving the messages on test. My problem is that I would like, once the person presses submit they are then taken to a confirmation page eg contact2.html Can anyone please help me on this? At the moment it just echo's to thank you message Many thanks Allan Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/ Share on other sites More sharing options...
the182guy Posted April 11, 2010 Share Posted April 11, 2010 Use a header() redirect after you have done the processing code. <?php header("Location: thankyou.html"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?> Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/#findComment-1040078 Share on other sites More sharing options...
ruralscot Posted April 11, 2010 Author Share Posted April 11, 2010 hi 182guy ok i'll explain I am a complete php newbie This is the simple code I have at present:- <?php { $to = "myemailaddress"; $subject = "Enquiry"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['enquiry']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; mail($to, $subject, $body); } ?> Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/#findComment-1040079 Share on other sites More sharing options...
the182guy Posted April 11, 2010 Share Posted April 11, 2010 Ok so after the mail() line, just call header() like mail($to, $subject, $body); header("Location: thankyou.html"); /* Redirect browser to thankyou.html */ /* Make sure that code below does not get executed when we redirect. */ exit; Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/#findComment-1040081 Share on other sites More sharing options...
ruralscot Posted April 11, 2010 Author Share Posted April 11, 2010 Hi again...dunce here again Ok now i get the following Warning: Cannot modify header information - headers already sent by (output started at /home/sites/allanlaw.co.uk/public_html/mailer.php:2) in /home/sites/allanlaw.co.uk/public_html/mailer.php on line 13 Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/#findComment-1040084 Share on other sites More sharing options...
ruralscot Posted April 11, 2010 Author Share Posted April 11, 2010 this is the coding I have in mailer.php <?php { $to = "[email protected]"; $subject = "Enquiry"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['enquiry']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; mail($to, $subject, $body); header("Location: contact2.html"); /* Redirect browser to thankyou.html */ /* Make sure that code below does not get executed when we redirect. */ exit; } ?> Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/#findComment-1040087 Share on other sites More sharing options...
the182guy Posted April 11, 2010 Share Posted April 11, 2010 You can't use header() after any output has been sent to the browser. You must have some HTML being outputted before the header() call. Need to show the rest of your code to be able to find it. Are they any includes at the top of mailer.php? Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/#findComment-1040088 Share on other sites More sharing options...
ruralscot Posted April 11, 2010 Author Share Posted April 11, 2010 Hi again Ok this is part of this page www.allanlaw.co.uk/contact.html and the mailer.php file is:- <?php { $to = "[email protected]"; $subject = "Enquiry"; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['enquiry']; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; mail($to, $subject, $body); header("Location: contact2.html"); /* Redirect browser to contact2.html */ /* Make sure that code below does not get executed when we redirect. */ exit; } ?> The actual contact page code is:- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Photography - Contact</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="../style/style.css" /> <link rel="stylesheet" type="text/css" href="../style/colour.css" /> </head> <body> <div id="logo"> <h1>ruralscotland photography</h1> <div id="links"></div> </div> <div id="menu"> <ul> <li><a href="../index.html">home</a></li> <li><a href="http://www.allanlaw.co.uk/pricing.html">pricing</a></li> <li><a class="selected" href="http://www.allanlaw.co.uk/contact.html">contact</a></li> </ul> </div> <div id="site_content"> <div id="side_menu"> <div class="side_menu_item"> <img src="../style/series_one.jpg" alt="" width="142" height="50" /> <span class="info">Wedding</span> </div> <div class="side_menu_item"> <a href="land.html"><img src="../style/series_two.jpg" alt="" width="142" height="50" /></a> <span class="info">Landscapes</span> </div> <div class="side_menu_item"> <a href="comm.html"><img src="../style/series_three.jpg" alt="" width="142" height="50" /></a> <span class="info">Commission</span> </div> <div class="side_menu_item"> <img src="../style/series_four.jpg" alt="" width="142" height="50" /> <span class="info">Playtime</span> </div> <div class="side_menu_item"> <img src="../style/series_five.jpg" alt="" width="142" height="50" /> <span class="info">Misc</span> </div> </div> <div id="content"> <h1>contact</h1> <p>Contact form: Please complete or simply email [email protected], if sending form please be sure to check SPAM folder as sometimes our email address can be treated as SPAM.</p> <p></p> <form id="contact" method="post" action="mailer.php"> <div class="row1"> <span class="formlabel">your name</span> <span class="forminput"> <input type="text" name="name" /> </span> </div> <div class="row1"> <span class="formlabel">your email address</span> <span class="forminput"> <input type="text" name="email" /> </span> </div> <div class="row1"> <span class="formlabel">your enquiry</span><span class="forminput"> <textarea cols="28" rows="11" name="enquiry" class="textarea"></textarea> </span></div> <div class="spacer"> </div> <div class="row1"> <span class="formlabel"></span><span class="forminput"> <input type="submit" value="submit" class="submit" /> </span></div> </form> </div> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/#findComment-1040090 Share on other sites More sharing options...
the182guy Posted April 11, 2010 Share Posted April 11, 2010 It looks like you might have some space before the <?php tag in your mailer.php file. Make sure there is no whitespace before the open page tag: <?php If there is, then the whitespace will be treated as output and sent to the browser. Are there any other error messages? Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/#findComment-1040098 Share on other sites More sharing options...
ruralscot Posted April 11, 2010 Author Share Posted April 11, 2010 lol...many thanks that man....what a divvy here...all sorted now thanks Link to comment https://forums.phpfreaks.com/topic/198233-form-help-with-confirmation-page/#findComment-1040102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.