无法使用PHP获取页面重定向

时间:2014-02-24 01:37:01

标签: php forms redirect

表单上的所有内容都可以使用,但不会重定向到其他页面。它继续发短信。我添加了header('Location: http://mywebsite.com/');但没有运气。我是PHP的新手,非常感谢帮助修复此代码。

当前代码:

<?php 


if(isset($_POST['email'])) {        

   $email_to = "me@email.com";     
   $email_subject = "Contact Request";                 

   function died($error) {                
      echo "We are very sorry, but there were error(s) found with the form you submitted. ";         
      echo "These errors appear below.<br /><br />";         
      echo $error."<br /><br />";         
      echo "Please go back and fix these errors.<br /><br />";         
      die();
   }

   if( !isset($_POST['full_name']) ||         
       !isset($_POST['agency']) ||   
       !isset($_POST['title']) ||         
       !isset($_POST['email']) ||       
       !isset($_POST['phone']) ||         
       !isset($_POST['comments'])) {         
     died('We are sorry, but there appears to be a problem with the form you submitted.');            
   }       

   $full_name = $_POST['full_name']; // required     
   $agency = $_POST['agency']; // required  
   $title = $_POST['title']; // required        
   $email = $_POST['email']; // required     
   $phone = $_POST['phone']; // not required     
   $comments = $_POST['comments']; // required

   $email_message = "Form details below.\n\n";           

   function clean_string($string) {       
      $bad = array("content-type","bcc:","to:","cc:","href");       
      return str_replace($bad,"",$string);     
   }           

   $email_message .= "Name: ".clean_string($full_name)."\n";     
   $email_message .= "Agency: ".clean_string($agency)."\n";     
   $email_message .= "Title: ".clean_string($title)."\n";    
   $email_message .= "Email: ".clean_string($email)."\n";     
   $email_message .= "phone: ".clean_string($phone)."\n";     
   $email_message .= "Comments: ".clean_string($comments)."\n";             

   $headers = 'From: '.$email_from."\r\n". 
              'Reply-To: '.$email_from."\r\n" . 
              'X-Mailer: PHP/' . phpversion(); 
   @mail($email_to, $email_subject, $email_message, $headers);   
   header('Location: http://mywebsite.com/'); 
?>
<?php } ?>

2 个答案:

答案 0 :(得分:0)

您的问题或代码的一部分中最后一行代码是拼写错误吗?

<?php } ?>

如果它真的是你的代码的一部分,那么php会尝试执行'}'并且最有可能搞砸了。 您没有说明您收到的短信是什么。

答案 1 :(得分:0)

只需删除?&gt;在这一行之后

标题('位置:http://mywebsite.com/');