beaner_06 Posted July 21, 2009 Share Posted July 21, 2009 How would I do a redirect on a contact form after a user successfully submits the form. I tried doing a header Location:, but I received that error. Basically I don't want to display just the Success! text, I want to redirect. Here is my code: <?php if(isset($_POST['submit'])) { $to = "ryanbuening@gmail.com"; $subject = "ryanbuening.com Contact Form"; $firstname_field = $_POST['first']; $lastname_field = $_POST['last']; $email_field = $_POST['email']; $comments = $_POST['comments']; $body = " From: $firstname_field $lastname_field\n E-Mail: $email_field\n Comments: $comments"; echo "Success!"; header ("Location: http://www.ryanbuening.com"); mail($to, $subject, $body); } else { echo "blarg!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/166820-redirect-q-warning-cannot-modify-header-information/ Share on other sites More sharing options...
ignace Posted July 21, 2009 Share Posted July 21, 2009 echo "Success!"; header ("Location: http://www.ryanbuening.com"); Chicken and egg problem You want to display a success text however you also want to redirect the user but you can't as you have already sent information How about: <a href="somewhere">Proceed</a> Or before you output succes: header('Refresh: 0; URL=somewhere'); Increase 0 if it needs to wait longer Quote Link to comment https://forums.phpfreaks.com/topic/166820-redirect-q-warning-cannot-modify-header-information/#findComment-879678 Share on other sites More sharing options...
timmah1 Posted July 21, 2009 Share Posted July 21, 2009 Use a refresh instead echo "Success!"; echo "<meta http-equiv=\"refresh\" content=\"3;URL=index.php\">"; mail($to, $subject, $body); } else { echo "blarg!"; } Quote Link to comment https://forums.phpfreaks.com/topic/166820-redirect-q-warning-cannot-modify-header-information/#findComment-879679 Share on other sites More sharing options...
rhodesa Posted July 21, 2009 Share Posted July 21, 2009 or just don't echo Success... Quote Link to comment https://forums.phpfreaks.com/topic/166820-redirect-q-warning-cannot-modify-header-information/#findComment-879683 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.