将重定向添加到PHP脚本

将重定向添加到PHP脚本,php,Php,我正在尝试将重定向添加到以下脚本的URL。单击按钮后,我似乎无法使其工作。有什么建议可以让它工作吗?提前谢谢 if ($Email=="") { echo "<div class='alert alert-error'> <a class='close' data-dismiss='alert'>×</a> <strong>Warning!</strong> Please ente

我正在尝试将重定向添加到以下脚本的URL。单击按钮后,我似乎无法使其工作。有什么建议可以让它工作吗?提前谢谢

if ($Email=="") {
    echo "<div class='alert alert-error'>
            <a class='close' data-dismiss='alert'>×</a>
            <strong>Warning!</strong> Please enter your email.
        </div>

    ";
}   
elseif ($Name=="" or $PhoneDay=="") {
    echo "<div class='alert alert-error'>
            <a class='close' data-dismiss='alert'>×</a>
            <strong>Warning!</strong> Fill all the required fields.
        </div>";
}   
else{
    mail($to, $subject, $msg, "From: $_REQUEST[Email]");
    echo "<div class='alert alert-success'>
            <a class='close' data-dismiss='alert'>×</a>
            <strong>Thank you!</strong>
        </div>";
    header("Location: http://www.example.com");
}
if($Email==“”){
回声“
×
警告!请输入您的电子邮件。
";
}   
elseif($Name==“”或$PhoneDay==“”){
回声“
×
警告!填写所有必填字段。
";
}   
否则{
邮件($to$subject$msg,“发件人:$\u请求[电子邮件]”);
回声“
×
谢谢!
";
标题(“位置:http://www.example.com");
}

?>

发出任何内容后,不能发送标题。因此,重定向之前没有回音。

这是header()的文档


正如PHP所说,在为用户返回任何输出之前,必须设置标题。您必须删除回音才能使其工作。

尝试以下操作:

 print '<script language="Javascript">document.location.href="http://example.com/";</script>';
print'document.location.href=”http://example.com/";';
确保您在网页上有以下内容:

<script type="text/javascript">

您可以使用输出控制功能阻止任何缓冲区。 在这里阅读更多

在您的情况下,您只能使用javascript重定向用户,否则您必须重新设计应用程序

而不是

header("Location: http://www.example.com");
用这个

die ("<script> top.location.href='http://www.example.com' </script>");
die(“top.location.href=”http://www.example.com' ");

这就是您的全部代码吗?电子邮件发送吗?你看到你的HTML输出了吗?内容回显后无法发送标题。哦,对不起,是的,电子邮件会发送,但我得到的是HTML输出。警告:无法修改标题信息-标题已由第43行/home/content/52/9448852/html/vision/send_mail.php:42)中的/home/content/52/9448852/html/vision/send_mail.php发送