Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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
PHP联系人表单提交时返回错误_Php_Html_Forms_Contact - Fatal编程技术网

PHP联系人表单提交时返回错误

PHP联系人表单提交时返回错误,php,html,forms,contact,Php,Html,Forms,Contact,因此,我尝试在两台不同的服务器上发布一个带有PHP联系人表单的页面,但这两台服务器都无法正常工作 服务器1: 提交时返回500内部错误页面。 我联系了网络支持,他们回复说我有: 脚本“index.php”的标题格式不正确:错误的标题: 我的index.php代码如下所示: <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $query

因此,我尝试在两台不同的服务器上发布一个带有PHP联系人表单的页面,但这两台服务器都无法正常工作

服务器1:
提交时返回
500内部错误
页面。
我联系了网络支持,他们回复说我有:

脚本“index.php”的标题格式不正确:错误的标题:

我的index.php代码如下所示:

    <?php
 if(isset($_POST['submit']))
 {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $query = $_POST['message'];
    $email_from = $name.'<'.$email.'>';

 $to="testemail@email.com";
 $subject="test subject";
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 $headers .= "From: ".$email_from."\r\n";
 $message="   

         Name:
         $name     
         <br>
         Email:
         $email        
         <br>
         Message:
         $query        

   ";
    if(mail($to,$subject,$message,$headers))
        header("Location:../contact.php?msg=Successful Submission!<br />
 Thank you for contacting us.");
    else
        header("Location:../contact.php?msg=Error To send Email !");
 }
?>

服务器2:
正确地将我链接到我的“谢谢页面”,但它正在显示 “发送电子邮件时出错!”而不是 “成功提交!”


任何帮助或建议都将不胜感激

问题似乎是标题位置重定向调用,该调用应提供完整的url,例如:

header("Location: http://www.example.com");
相对URL按照浏览器的最大努力进行处理,而您的浏览器显然不喜欢../,因此出现了“坏标题”投诉


这一点已在页面上注明。

我认为问题在于这一部分:

 if(mail($to,$subject,$message,$headers))
        header("Location:../contact.php?msg=Successful Submission!<br />
 Thank you for contacting us.");
    else
        header("Location:../contact.php?msg=Error To send Email !");
if(邮件($to、$subject、$message、$headers))
标题(“位置:../contact.php?msg=成功提交!
感谢您与我们联系。”); 其他的 标题(“位置:../contact.php?msg=发送电子邮件时出错!”);
具体在
标题()中

  • 每个空格将转换为%20,因为没有带空格的URL
  • 没有像!在URL中

  • 中的“/”将建议使用一个名为“>的文件,感谢您与我们联系。”
  • 退房:


    同时放入
    exit()以防止进一步执行脚本

    忽略以下答案中所述内容(1.在
    标题(“位置:…);
    和2.
    urlencode()
    您的查询字符串中使用绝对URI),如果您想发送标题,您需要在PHP开始标记之前修剪前导空格。除了答案之外,请确保您上面介绍的代码显示在页面的最上面。@Melvalous没问题