Php 表单提交后重定向在IE中不起作用,但在chrome中起作用

Php 表单提交后重定向在IE中不起作用,但在chrome中起作用,php,forms,redirect,Php,Forms,Redirect,我创建了一个from,在成功提交后显示一个“谢谢”页面。 验证表单字段并将其上载到服务器时成功 在所有浏览器中,邮件和附件都被正确发送-我收到了发送到收件箱的电子邮件,但是在FireFox和Chrome中,我在成功提交后被重定向到“谢谢”页面。 在IE 11中,它根本不是重定向 此页面的链接为: 我使用ob_start();&ob_flush();为了安全起见,在“谢谢”页面上 表格定义如下: /_scripts/uploadAndSend.php“enctype=“multipart/for

我创建了一个from,在成功提交后显示一个“谢谢”页面。 验证表单字段并将其上载到服务器时成功

在所有浏览器中,邮件和附件都被正确发送-我收到了发送到收件箱的电子邮件,但是在FireFox和Chrome中,我在成功提交后被重定向到“谢谢”页面。 在IE 11中,它根本不是重定向

此页面的链接为:

我使用ob_start();&ob_flush();为了安全起见,在“谢谢”页面上

表格定义如下:

/_scripts/uploadAndSend.php“enctype=“multipart/form data”>

这是提交功能:

$('form[name="formmail"]').submit(function (event) {
  "use strict";
  event.preventDefault(); //prevent default action 
  if (!checkForm()) {
    return false;
  } else {
    console.log("passed check");
    var post_url = $(this).attr("action"); //get form action url
    var request_method = $(this).attr("method"); //get form GET/POST method
    //form_data.append('language', $('input[name=language]')[0]);

    // Attach file
    var form_data = new FormData();
    var myform = $('form[name="formmail"]'); // specify the form element
    //var myform = $("#formmail"); // specify the form element
    var idata = myform.serializeArray();
    var file_data = $("#browseButton").prop("files")[0];

    form_data.append("fileatt", file_data);

    $.each(idata, function (key, input) {
      form_data.append(input.name, input.value);
    });
    //alert(form_data);
    $.ajax({
      url: post_url,
      //type: "POST",
      //dataType:'json',
      type: request_method,
      data: form_data,
      contentType: false,
      processData: false,
      xhr: function () {
        //upload Progress

        var xhr = $.ajaxSettings.xhr();
        if (xhr.upload) {
          xhr.upload.addEventListener("progress", function (event) {

            var percent = 0;
            var position = event.loaded || event.position;
            var total = event.total;
            if (event.lengthComputable) {
              percent = Math.ceil(position / total * 100);
            }
            //update progressbar
            $(".progress-bar").css("width", percent + "%");
            $(".progress-bar").html(percent + "%");
            //$("#upload-progress .progress-bar").css("width", + percent +"%");
          }, true);
        }
        return xhr;
      }
    }).done(function (response) { //
      $("#server-results").html(response);
    });
  }
});
///////// 此时会重定向到Thankyu页面:

<?php ob_start(); ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
<?php 
    $host = $_SERVER['HTTP_HOST'];
    if(strpos($host, "dnd-production.com") !== false){  
        $site_Root = "http://$host";
    } else {
        $uri   = explode("/", $_SERVER['PHP_SELF']);
        //print_r($uri);
        $site_Root = "//$host/$uri[1]/";
    }

    if(isset($_GET['lang'])) {
      $lang = $_GET['lang'];
    } else {
      $lang = "he"; 
    }
    if($lang == "en") {
        $thankYouPage = "${site_Root}/_english/thankyou.php?page=null";
    } else {
        $thankYouPage = "${site_Root}/_pages/thankyou.php";
    }
    echo "<meta http-equiv=\"refresh\" content=\"0; url=$thankYouPage\">";
?>

<title>Email Form</title>
</head>

<body onLoad="Refresher(1)">
<?php

$to = 'info@dnd-production.com';

$name           = $_POST['name'];
$email          = $_POST['email'];
$subject        = $_POST['subject'];
$comments   = $_POST['message'];
$phone          = $_POST['phone'];
$from           = $email;
$lang           = $_POST['language'];

// Get html message content
$form_data  = "<p>This email is from <span class=\"bold\">$name</span></p> \n\n ";
$form_data .= "<p>Phone: $phone</p>";
$form_data .= "<p>Email: $email</p>";
$form_data .= "<h3>$subject</h3>";
$form_data .= "<p>$comments</p>";
$message =    "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \n" .
                  "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> \n" .
                  "<html xmlns=\"http://www.w3.org/1999/xhtml\"> \n" .
                  "<head> \n" .
                  "  <meta http-equiv=\"content-type\" content= \n" .
                  "  \"text/html; charset=UTF-8\" /> \n" .
                  "<style type=\"text/css\"> \n" .
                  "body {    font-size: 9pt; font-family:  verdana, sans-serif;     color: #000; background:#fff; }  \n" .
                  ".bold { font-weight: bold; }  \n" .
                  "</style>  \n" .
                  "</head> \n" .
                  "<body>$form_data \n" .
                  "</body> \n" .
                  "</html> \n\n";

$headers = "From: $from";
// Obtain file upload vars
if(isset($_FILES['fileatt'])){  
  $fileatt      = $_FILES['fileatt']['tmp_name'];
  $fileatt_type = $_FILES['fileatt']['type'];
  $fileatt_name = $_FILES['fileatt']['name'];
  $fileatt_size = $_FILES['fileatt']['size']/1024;//size in KBs

  if (is_uploaded_file($fileatt)) {
    // Read the file to be attached ('rb' = read binary)
    $file = fopen($fileatt,'rb');
    $data = fread($file,filesize($fileatt));
    fclose($file);
    // Generate a boundary string
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    // Add the headers for a file attachment
    $headers .= "\nMIME-Version: 1.0\n" .
             "Content-Type: multipart/mixed;\n" .
             " boundary=\"{$mime_boundary}\"";
    // Add a multipart boundary above the html message
    $message = "This is a multi-part message in MIME format.\n\n" .
           "--{$mime_boundary}\n" .
           "Content-Type: text/html; charset=\"UTF-8\"\n" .
           "Content-Transfer-Encoding: 7bit\n\n" .
           $message . "\n\n";

    // Base64 encode the file data
    $data = chunk_split(base64_encode($data));
    //We now have everything we need to write the portion of the message that contains the file attachment. Here's the code:
    //Add file attachment to the message
    $message .= "--{$mime_boundary}\n" .
              "Content-Type: {$fileatt_type};\n" .
              " name=\"{$fileatt_name}\"\n" .
              "Content-Disposition: attachment;\n" .
              " filename=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" .
              $data . "\n\n" .
              "--{$mime_boundary}--\n";
  }
}
//end if is_uploaded_file
else {
  // Generate a boundary string
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  // Add the headers for a file attachment
  $headers .= "\nMIME-Version: 1.0\n" .
              "Content-Type: multipart/mixed;\n" .
              " boundary=\"{$mime_boundary}\"";
  // Add a multipart boundary above the html message
  $message = "This is a multi-part message in MIME format.\n\n" .
             "--{$mime_boundary}\n" .
             "Content-Type: text/html; charset=\"UTF-8\"\n" .
             "Content-Transfer-Encoding: 7bit\n\n" .
             $message . "\n\n";
}                        
mail($to, $subject, $message, $headers);
?>
</body>
</html>
<? ob_flush(); ?>

电子邮件表格
试试这个:

echo '<meta http-equiv="refresh" content="0;URL='.$thankYouPage.'" />';
echo';
对于旧版本,请使用:

echo '<meta http-equiv="refresh" content="0;URL='.$thankYouPage.'" /> </meta>';
echo';

为什么不使用标题进行重定向

而不是

if($lang == "en") {
        $thankYouPage = "${site_Root}/_english/thankyou.php?page=null";
    } else {
        $thankYouPage = "${site_Root}/_pages/thankyou.php";
    }
    echo "<meta http-equiv=\"refresh\" content=\"0; url=$thankYouPage\">";

IE版本有多旧?如果你在使用PHP…为什么不正确地使用HTTP?你的重定向脚本看起来有点疯狂…它不应该输出任何东西(甚至不是空的HTML页面)当运行sendmail时,它可以被客户端缓存/重新加载到浏览器中,这是你不想要的。这是我从internet上复制的脚本。你会怎么做呢?这会在当前页面的末尾添加“谢谢”页面page@dandan你能帮我倒垃圾吗;并共享您得到的URL?我很快会这样做,但它必须是正确的,因为我在chrome和firefox中都得到了正确的响应。您不这么认为吗?它给出了:string(45)“,这是正确的地址我想它是:
if($lang == "en") {
    $thankYouPage = "${site_Root}/_english/thankyou.php?page=null";
} else {
    $thankYouPage = "${site_Root}/_pages/thankyou.php";
}
header('Location: ' . $thankYouPage);
 exit();