提交时,表单将返回send.php而不是contact.php,因此显示为空白

时间:2013-11-06 22:42:20

标签: php

我查看了类似问题的帖子,但我对PHP很新,我似乎无法弄清楚如何解决我的问题,所以谢谢你的耐心!!

我在youtube上做了一个教程来创建我的联系表单,它运行良好(内容传输),但是,一旦点击提交按钮,一条消息应该显示在页面顶部,表明消息是发送成功或提交内容有问题 - 而只是转到空白页面,以便人们不知道表单是否已经通过。我可以看到,一旦提交被点击,网址显示为www.communicatingwell.com/send.php,它应该仍然在www.communicatingwell.com/contact.php但是从我在“位置”下看到的它是指向contact.php,所以我不确定错误在哪里。

我一直试图解决这个问题大约一个星期了,感到难过。希望有人能给我一些建议。谢谢!!!!!!

表单位于此处:http://www.communicatingwell.com/contact.php

来自contact.php文件:

<?
$s=$_GET['s'];
if($s="1")
{echo('<span class="success">Your email has been sent to our web team. Please allow a           24 hour response time </span>');}
else if($s="2")
{echo('<span class="fail">Sorry ! Your message has not been sent to our web team.     Please fill the form correctly and try again </span>');}
?>

和我脑中的css一样:

<style type="text/css">
.success {
color: #333300;
margin-left: 15px;
}
.fail {
color: #993300;
margin-left: 15px;
}
</style>

send.php文件:

<?
$email = $_POST['email'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$messages = $_POST['messages'];
$city = $_POST['city'];
$comments = $_POST['comments'];
$security = $_POST['security'];

$to = "info@communicatingwell.com";
$subject = "New Contact Form Submission";
$message = "A visitor of communicatingwell.com has submitted the following information.\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessages: $messages\n\nCity: $city\n\nComments: $comments\n\nPlease respond to this enquiry within 48 hours";

if($security=="10"){
mail($to,$subject,$message);
header("location:contact.php?s=1");
}
else{
header("location:contact.php?s=2");
}
?>

1 个答案:

答案 0 :(得分:0)

我不得不说这是一个错误,因为需要先分配$security$security = $_POST['security'];位于顶部。

像这样。

<?php 
  $security = $_POST['security'];
  if($security=="10"){
    mail($to,$subject,$message);
    header("location:contact.php?s=1");
  }
  else{
    header("location:contact.php?s=2");
  }
?>