PHP重定向不适用于IE?
我尝试将脚本发送电子邮件并重定向到主页面。是的,这是工作!但...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
}
?>
我怎么能解决呢?
请使用下面的代码
header('Location:http://www.abc.com/Contact.html')
exit;
就像我向你展示的代码已经在Chrome和Firefox上工作一样。但是在IE甚至退出上没有工作;被添加。 – fronthem 2013-03-21 09:11:52
使用此代码,而不是
die(header('Location:http://www.abc.com/Contact.html'));
可以省略die()
,但在这里很有用,因为用它可以防止脚本发送重定向报头之后运行。
的答案真的,没有工作。 – fronthem 2013-03-21 09:01:52
然后你应该尝试使用循序渐进的检查。注释标题行并放置此行:'die('mail'with'。(bool)$ mailSentRes。'result');'只是为了确保在脚本中获得这一点。 – 2013-03-21 09:39:34
使用@关闭'mail()'不是个好主意。也许它有话要说。 – 2013-03-21 09:45:56
变化
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
这帮助我解决了我遇到的一个问题。显然,IIS搞乱了IE浏览器的重定向。 Refresh方法在Location方法不工作的情况下工作。 – dVyper 2016-07-29 15:06:59
您是否尝试使用exit()函数退出头部函数之后的脚本; ? – 2013-03-21 08:50:09
使用这里找到的:http://en.wikipedia.org/wiki/Meta_refresh(' Najzero 2013-03-21 08:52:06
@Stoyan Dimov是的,试试吧。 – fronthem 2013-03-21 09:00:10