-2

Im trying to redirect the user after submitting a form. Im currently using Header("Location:http://www.google.com") as a test, but it stays on my site after submitting.

What am I doing wrong?

<?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: Website'; 
    $to = 'contact@joakimsorensen.se'; 
    $subject = 'Hello';
    $human = $_POST['human'];


    $body = "From: $name\n E-Mail: $email\n Message:\n $message";



     if ($_POST['submit'] && $human == '4') {

    if (mail ($to, $subject, $body, $from)) {

    header("Location: http://www.google.com");
    echo 'great';
    } else { 
        echo '<span style="color:red"><p>Something went wrong, go back and try again!</p></span>'; 
    }
     } else if ($_POST['submit'] && $human != '4') {
    echo '<span style="color:red"><p>You answered the anti-spam question incorrectly!</p></span>';
    }
?>

It just prints out "great" from the echo.

Stubborn
  • 995
  • 4
  • 17
  • 30
  • Try using single quotes `''` instead of `""`. – smr5 Nov 09 '14 at 15:34
  • instead of `echo 'great';` try die(); ref : [http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php][1] [1]: http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php – Rajarshi Goswami Nov 09 '14 at 15:37

1 Answers1

-1

I think the problem is that the header is already sent. Try to use

?>
<script type="text/javascript">
   window.location="http://www.google.com";
</script>
<?php

instead of

 header("Location: http://www.google.com");
pbaldauf
  • 1,671
  • 2
  • 23
  • 32