2013-06-11 116 views
0

我已经在PHP中创建了一个联系表单。表单工作正常,并发送消息,但当我尝试将用户重定向到我的谢谢页面时,我收到一个头文件已发送消息。提交后重定向表单感谢页面

我开始形式:

<form name="myform" id="myform" class="form-foot" action="/receiving.php" method="post"> 

而对于receiving.php的PHP代码:

<?php 

$name = $_POST['name']; 
$email = $_POST['email']; 
$message = $_POST['message']; 

if(isset($_POST['submit'])) 

{ 
$from_add = "[email protected]"; 

$to_add = "[email protected]"; 

$subject = "Contact Form"; 

$message = " 
Name:$name \n 
Email: $email \n 
Message: $message \n 

$headers = "From: $from_add \r\n"; 
$headers .= "Reply-To: $from_add \r\n"; 
$headers .= "Return-Path: $from_add\r\n"; 
$headers .= "X-Mailer: PHP \r\n"; 


if(mail($to_add,$subject,$message,$headers)) 
{ 
    Header("Location: /thanks"); 
} 
} 


?> 

我怎样才能将用户重定向到成功提交后www.mysite.com/thanks?

+0

下面是解http://stackoverflow.com/questions/4459204/seeing-cannot-modify-header-information-error-when-attempting-to-redirect – Kevin

+1

当你去完成通过重复你可能想要读一些关于头部注入的主题 – PeeHaa

回答

0
  1. 确保header调用之前没有输出。任何回声或<?php之前的任何空间都会破坏它。

  2. header("location:...")需要绝对URI。

    header("location: http://www.site.tld/thanks"); 
    
  3. header("location: /thanks");应该有一个exit紧随其后。

    header("location: http://www.site.tld/thanks"); exit; 
    
+1

它不是关于在头后面放置'exit“,或者使用绝对URI我认为它是关于输出缓冲。 – samayo

+1

输出缓冲问题只是一个问题。如果我可以帮助更多的事情,那么我正在解决问题,而不仅仅是症状。 –

+0

嗨乔,我试过了,我仍然得到相同的错误:警告:不能修改标题信息 - 标题已发送 –

相关问题