2014-03-25 56 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>");