Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “提交”按钮发送邮件但不重定向?_Javascript_Php_Forms_Redirect - Fatal编程技术网

Javascript “提交”按钮发送邮件但不重定向?

Javascript “提交”按钮发送邮件但不重定向?,javascript,php,forms,redirect,Javascript,Php,Forms,Redirect,这个剧本快把我逼疯了。这是一个简单的提交表格。我点击submit按钮,包含所有提交信息的电子邮件就会生成 但是我没办法按一下按钮把我转到感谢页面 我试过PHP,我试过Javascript,我甚至试过老式的元重定向。什么都不管用 // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); mail(

这个剧本快把我逼疯了。这是一个简单的提交表格。我点击submit按钮,包含所有提交信息的电子邮件就会生成

但是我没办法按一下按钮把我转到感谢页面

我试过PHP,我试过Javascript,我甚至试过老式的元重定向。什么都不管用

// create email headers
$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://amvleague.vitaminh.info/thankyou.html")
}

die();
?>
我已尝试将标题部分放在文档顶部。我已尝试将其更改为:

echo '<script>document.location="page2.html"; </script>';
我已经用这个脚本生成了很多电子邮件,gmail现在把它们全部发送到垃圾邮件中。我不能让这该死的东西改变方向

如果有人能在我把眼睛挖出来之前帮上忙,我将不胜感激

编辑:我已经尝试了你们所有人的建议。这就好像脚本完全拒绝执行mail命令之后的任何内容。这有什么原因吗

编辑2:仍然没有任何工作

这是完整的脚本和Rolen Koh的修改。这里是否隐藏了阻止脚本访问邮件标记后面的任何内容的内容

<?php
if(isset($_POST['email'])) {
    $email_to = "pathos@vitaminh.info";
    $email_subject = "BelleCON 2014 - AMV League Submission";


    function died($error) {
        // your error code can go here
        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();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
    !isset($_POST['last_name']) ||
    !isset($_POST['handle']) ||
    !isset($_POST['amv_title']) ||
    !isset($_POST['amv_song']) ||
    !isset($_POST['amv_artist']) ||
    !isset($_POST['amv_anime']) ||
    !isset($_POST['amv_link']) ||
    !isset($_POST['amv_category']) ||
    !isset($_POST['email'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');       
}

function IsChecked($chkname,$value)
{
    if(!empty($_POST[$chkname]))
    {
        foreach($_POST[$chkname] as $chkval)
        {
            if($chkval == $value)
            {
                return true;
            }
        }
    }
    return false;
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$handle = $_POST['handle']; // not required
$amv_title = $_POST['amv_title']; // required
$amv_song = $_POST['amv_song']; // required
$amv_artist = $_POST['amv_artist']; // required
$amv_anime = $_POST['amv_anime']; // required
$amv_link = $_POST['amv_link']; // required
$amv_category = $_POST['amv_category']; // required
$email_from = $_POST['email']; // required


$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
$string_exp = "/^[A-Za-z .-]+$/";
  if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
    if(strlen($error_message) > 0) {
died($error_message);
  }
    $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($first_name).clean_string($last_name)."\n";
$email_message .= "Handle: ".clean_string($handle)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Title of AMV: ".clean_string($amv_title)."\n";    
$email_message .= "Category: ".clean_string($amv_category)."\n";
$email_message .= "Song: ".clean_string($amv_song)." by     ".clean_string($amv_artist)."\n";
$email_message .= "Anime Used: ".clean_string($amv_anime)."\n\n";
$email_message .= clean_string($amv_link)."\n";        

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail = mail($email_to, $email_subject, $email_message, $headers);  
if($mail)
{
header("location:http://amvleague.vitaminh.info/thankyou.html");
}

}    
}
?>
使用location.href

可以在不使用窗口前缀的情况下写入window.location对象


您可以使用header函数发送新的HTTP头,但这必须在任何HTML或文本之前发送到浏览器,例如在声明之前

试试这个,这就是我用的

 function redirect($url){
    if (headers_sent()){
      die('<script type="text/javascript">window.location.href="' . $url . '";</script>');
    }else{
      header('Location: ' . $url);
      die();
    }    
}
试试这个:

$mail = mail($email_to, $email_subject, $email_message, $headers);  
if($mail)
{
    header("location:http://amvleague.vitaminh.info/thankyou.html");
}
此外,您的标题位置中缺少分号:http://amvleague.vitaminh.info/thankyou.html 行,但我猜是打字错误。

header("location:http://amvleague.vitaminh.info/thankyou.html")
需要

header("Location: http://amvleague.vitaminh.info/thankyou.html");
注意大写字母L、冒号后的空格和结尾的分号

如果这不能解决您的问题,那么您在其他代码中也有问题。要找到它,您可以尝试查看php错误日志。如果您有权访问该服务器,您可以通过为特定服务器使用以下任何资源来找到它


如果您在共享主机上,他们可能有一些此文件的非标准位置,在这种情况下,最好联系他们并询问php错误日志的标准位置。

Pl检查您在此处给出的路径是否正确。删除标题前的空格。并尝试呼叫退出;在标题之后;我已经提出了一个答案。请检查以下内容并尝试。
header("Location: http://amvleague.vitaminh.info/thankyou.html");