Redirect Q - Warning: Cannot modify header information
Posted: Tue Jul 21, 2009 12:30 pm
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:
Code: Select all
<?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!";
}
?>