电子邮件发送后的php重定向问题

时间:2013-06-28 09:59:24

标签: php redirect header

我收到旧的标题问题只是无法重定向我如何修复它?

警告:无法修改标头信息 - 已发送的标头

<?php if (isset($_POST['email']))
{
  $content = '<html><body>';
  $content .= 'Email Address: '.$_POST['email'].'<br />';
  $content .= 'Enquiry Type: '.$_POST['enquiry'].'<br />';
  $content .= 'Message: '.$_POST['message'].'<br />';
  $content .= 'Telephone Number: '.$_POST['telephone'].'<br />';
  $content .= 'Preferred Contact Method:" '.$_POST['contact-method'] ;
  $content .= '</body></html>';
  $to = 'myemail*email.com';

$subject = 'Website Contact Form ';

$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (mail($to, $subject, $content, $headers)) {
header('Location:form-submitted.php');
    }

}
?>
<!DOCTYPE html>
<html>

7 个答案:

答案 0 :(得分:1)

这意味着已经发送了标头。 请试试这个

echo "<meta http-equiv='refresh' content=\"0; url=form-submitted.php\">";

答案 1 :(得分:0)

使用exit();标题功能之后。

header('Location:form-submitted.php');
exit();

答案 2 :(得分:0)

您有无效的电子邮件ID

$to = 'myemail*email.com';

$to = 'myemail@email.com';// @ in place of *

因此,mail在上述情况下会return false

答案 3 :(得分:0)

将这一行放在下面:

 ob_start();

在执行PHP文件的开头为我工作。

答案 4 :(得分:0)

//Put this code at the top of your page
<?php ob_start(); ?>

你的代码.....

//Put this code at the bottom of your page
<?php ob_flush(); ?>

答案 5 :(得分:0)

使用JS

if (mail($to, $subject, $content, $headers)) {   
?>
<script>window.location.replace("http://your url/");</script>
<?php 
}

答案 6 :(得分:0)

以下是说明:将所有可能打印到{strong>之前 header("Location: site.php")的网站上删除。这是因为http标头始终位于请求或响应的顶部。这意味着,如果您在设置标题之前在响应中回显或打印任何内容,则会产生以下结果:

HTTP/1.1 404 Not Found
Date: Sun, 18 Oct 2012 10:36:20 GMT
Server: Apache/2.2.14 (Win32)
Content-Length: 230
<p>this tag should not be here</p>
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML>
<html>
<head>
   <title>My site</title>
</head>
<body>
   <h1>Hello</h1>
   <p>Lorem ipsum</p>
</body>
</html>

您可以在上面看到的<p>元素,可能已经用php打印了出来,现在破坏了http响应。您要使用header();函数设置的任何内容都会引发错误。

我希望这会有所帮助:)

相关问题