PHP contact form -- Redirect instead of echo

Hi all, I have a contact form that works fine, but instead of a thank you message being created by "echo", I'd like to redirect the user to the thanks.php page. Here's my current code:
<?php
if(isset($_POST['submit'])) {
$to = "test@test.com";
$subject = "You've been contacted";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Thank you for contacting us. We will be in touch soon.";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>

Open in new window

tekgrlAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
steveo225Connect With a Mentor Commented:
You'll probably want to put that after the call to mail() just to be safe
0
 
steveo225Commented:
replace the echo with: header('Location: thanks.php');
0
 
tekgrlAuthor Commented:
Perfect. Thanks!
0
 
tekgrlAuthor Commented:
Perfect. Thanks!
0
All Courses

From novice to tech pro — start learning today.