2013-03-21 43 views
0

我嘗試將腳本發送電子郵件並重定向到主頁面。是的,這是工作!但...PHP重定向不適用於IE?

在IE上,它不起作用。

代碼示例:

<?php 
if(isset($_POST['email'])) { 

    // EDIT THE 2 LINES BELOW AS REQUIRED 
    //$email_to1 = "[email protected]"; 
    $email_to2 = "[email protected]"; 
    $email_subject = "Email from www.abc.com";   
    ................ 
    ................     
    // create email headers 
    $headers = 'From: '.$email_from."\r\n". 
    'Reply-To: '.$email_from."\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 
    //@mail($email_to1, $email_subject, $email_message, $headers); 
    @mail($email_to2, $email_subject, $email_message, $headers); 
    header("Refresh: 3; http://www.abc.com/Contact.html"); 
?> 

<!-- include your own success html here --> 

    Thank you for contacting us. We will be in touch with you very soon.<br> 
    <a href="http://www.abc.com/Contact.html">back to website</a> 
<?php 
} 
?> 

我怎麼能解決呢?

+0

您是否嘗試使用exit()函數退出頭部函數之後的腳本; ? – 2013-03-21 08:50:09

+1

使用這裏找到的:http://en.wikipedia.org/wiki/Meta_refresh(' Najzero 2013-03-21 08:52:06

+0

@Stoyan Dimov是的,試試吧。 – fronthem 2013-03-21 09:00:10

回答

2

請使用下面的代碼

header('Location:http://www.abc.com/Contact.html') 
    exit; 
+0

就像我向你展示的代碼已經在Chrome和Firefox上工作一樣。但是在IE甚至退出上沒有工作;被添加。 – fronthem 2013-03-21 09:11:52

0

使用此代碼,而不是

die(header('Location:http://www.abc.com/Contact.html')); 

可以省略die(),但在這裏很有用,因爲用它可以防止腳本發送重定向報頭之後運行。

+0

的答案真的,沒有工作。 – fronthem 2013-03-21 09:01:52

+0

然後你應該嘗試使用循序漸進的檢查。註釋標題行並放置此行:'die('mail'with'。(bool)$ mailSentRes。'result');'只是爲了確保在腳本中獲得這一點。 – 2013-03-21 09:39:34

+0

使用@關閉'mail()'不是個好主意。也許它有話要說。 – 2013-03-21 09:45:56

0

變化

header("Refresh: 3; http://www.abc.com/Contact.html"); 

header("Refresh: 3; URL=http://www.abc.com/Contact.html"); 

我認爲應該做的伎倆

還拿這個答案注:'Refresh' HTTP header和這條評論:'Refresh' HTTP header

+0

這幫助我解決了我遇到的一個問題。顯然,IIS搞亂了IE瀏覽器的重定向。 Refresh方法在Location方法不工作的情況下工作。 – dVyper 2016-07-29 15:06:59