Php标头位置重定向不工作的电子邮件注册


Php header location redirect not working on e-mail signup

 <?php
header("Location:http://www.website.com/");
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
  // detect & prevent header injections
  $test = "/(content-type|bcc:|cc:|to:)/i";
  foreach ( $_POST as $key => $val ) {
    if ( preg_match( $test, $val ) ) {
      exit;
    }
  }
  //
  mail( "andrewrichardgale@gmail.com", $_POST['subject'], $_POST['message'], "From:" . $_POST['email'] );
  //            ^
  //  Replace with your email 
}
?>

这个脚本正在工作,并将电子邮件保存到。txt,但是,我希望它转发到一个感谢页面,但是,重定向是不工作的,但注册。

我不懂PHP,我是从一个模板中使用的,所以我很感激任何帮助

您可以尝试:

header("Location: YOUR_PAGE");

echo "<script>window.location.href='YOUR_PAGE';</script>";

在邮件函数被调用之后。

我真的推荐第一个,因为它是PHP做你的工作,第二个依赖于JavaScript,所以它只在第一个不工作时使用。