0

I have a PHP contact form, and once a user has successfully filled out the form they see the "Message sent" message under the form.

PHP code

<?php 
if(isset($_POST['submit']) && !isset($name_error) && !isset($subject_error) && !isset($email_error) && !isset($message_error)){
  $to = 'youremail@addres.com'; // edit here
  $body = " Name: $name\n E-mail: $email\n Message:\n $message";
  if(mail($to, $subject, $body)){
    echo '<p style="color: green">Message sent</p>';
  }else{
    echo '<p>Error occurred, please try again later</p>';
  }
}
?>

However, refreshing the form after the form has been submitted the page would send the form details again and again. How can I redirect a user to say: http://www.example.com/thanks after they have submitted the form successfully?

EDIT: I am not sure how to redirect within the form itself, I know how to redirect with PHP, just not in this script.

Emma Stone
  • 135
  • 1
  • 11
  • `header("Location: https://www.google.com");` This must be called before any other output is sent. – Matt Clark Apr 10 '17 at 17:25
  • Thank you Matt, So remove the echo and replace with header("Location: https://www.google.com"); ? Sorry not a PHP pro. – Emma Stone Apr 10 '17 at 17:26

0 Answers0