2014-03-25 58 views
-1

我试图将重定向添加到以下脚本的URL。点击按钮后,我似乎无法使其工作。有关如何使其工作的任何建议?提前致谢!添加重定向到PHP脚本

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"); 
} 

?>

+0

那是所有的代码?电子邮件是否发送?你看到你的HTML输出吗?内容被回显后,不能发送 –

+1

标题。 – cmbuckley

+0

哦,对不起,是的,电子邮件发送,但在我得到的HTML输出。警告:无法修改标头信息 -/home/content/52/9448852/html/vision/send_mail中已经由(home/content/52/9448852/html /vision/send_mail.php:42开始的输出)发送的标头。第43行的php – user3461850

回答

0

尝试这样:

print '<script language="Javascript">document.location.href="http://example.com/";</script>'; 

请确保您有这个网页上:

<script type="text/javascript"> 
0

你发出什么后,您不能发送头。所以,重定向之前没有回声。

0

可以使用输出控制功能,防止任何缓冲。 在这里阅读更多http://www.php.net/manual/en/ref.outcontrol.php

在你的情况你只能使用javascript重定向用户,否则你不得不重新设计应用程序。

而不是

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

使用本

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