Php 提交时无法重定向

Php 提交时无法重定向,php,forms,redirect,header,Php,Forms,Redirect,Header,我有一个基本的表单,我试图重定向到一个与提交时的索引页面不同的页面。我只能得到这个: header("Location: http://www.mysite.com/thanks.php"); 当我把它放在上面工作 <!doctype html> 但这在IE中不起作用,我收到HTML5验证错误 这是我的密码: 在页面顶部: <?php include("functions/contactfunctions.php"); ?> 再

我有一个基本的表单,我试图重定向到一个与提交时的索引页面不同的页面。我只能得到这个:

 header("Location: http://www.mysite.com/thanks.php"); 
当我把它放在上面工作

 <!doctype html>

但这在IE中不起作用,我收到HTML5验证错误

这是我的密码: 在页面顶部:

   <?php
  include("functions/contactfunctions.php"); 



   ?>

再往下看:

  <?php
    if($_POST['submitted'] == "contactus")
    {
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];

    $email = $_POST['email'];
    $message = $_POST['message'];
    $location = $_POST['location'];
            if(!$firstname)
    $error = "Please enter your first name.";
    else
    if(!$lastname)
    $error = "Please enter your last name.";
    else
    if(!$email)
    $error = "Please enter a valid email.";
    else
    if(!$message)
    $error = "Please enter your message.";
    else
    if(!$location)
    $error = "Please tell us where you're from.";


    }
  ?>

    <?php
       if($_POST['submitted'])
       {
      ContactMessage($firstname, $lastname, $email, $message, $location);
        header("Location:http://www.mywebsite.com/thanks.php");
       exit;
    }

 ?> 

在开头之前有空格
请在开头之前删除空格和换行符

<?php
If header();如果没有重定向页面,则表示表单没有按应有的方式提交。
我建议您检查表单中的所有输入,而不是检查$u POST['submitted']

if($_POST['email']&&$_POST['message']/* And so on... */){
   echo "echo something here so you know it ACTUALLY HAS been submitted.";
}
提示:使用header()时;确保使用ob_start();和ob_flush();像这样:

//Start of script
ob_start();

//Now header(); will work efficiently here inside your functions...

//End of script
ob_flush();

我很抱歉;不知道你说的空格是什么意思?空间从什么到什么?和顶部@user1505573:在两个页面上;在@user1505573的
前面的两个空格:如果我将标题放在doctype之前,第一个
会起作用,但在w3验证时出现了这个错误,“在doctype之前看到的注释。Internet explorer将进入怪癖模式。”我添加了这个-加上删除空白,现在似乎可以起作用了。谢谢
//Start of script
ob_start();

//Now header(); will work efficiently here inside your functions...

//End of script
ob_flush();