contact form PHP redirect is not working

前端 未结 7 405
迷失自我
迷失自我 2021-01-20 01:42

I im trying to redirect to my homepage after submitting a message on my contact form, the form sends the email but I get this message:

Array
(
    [name] =&g         


        
7条回答
  •  [愿得一人]
    2021-01-20 02:00

    Headers are used to communicate with your client's browser. They're like little commands that the browser will perform when received. When you output any data (text,numbers,whatever), you're client's browser will print that data. After that, the browser will no longer be interested in any headers you send.

    The header() function is a function used to send custom headers. So when this function is called, headers are sent out to your client's browser.

    Now you have a very brief understanding of what it is you're actually trying to do, you should be able to see where your problem lies.

    You are outputting other data before sending those custom headers. This is what's triggering the error.

    So this:

    echo "
    ";
    print_r($_POST);
    

    Should not be before this:

    header('Location:mydomain');
    

提交回复
热议问题