0

我浏览过有类似问题的帖子,但对 PHP 太陌生了,我似乎仍然无法弄清楚如何解决我的问题,所以感谢您的耐心等待!

我在 youtube 上做了一个教程来创建我的联系表单,它运行良好(内容传输),但是,一旦点击提交按钮,一条消息应该显示在页面顶部,说明消息已成功发送或提交有问题 - 相反,它只是进入一个空白页面,因此人们不知道表单是否已通过。我可以看到,一旦提交被击中,该 URL 将显示为 www.communicatingwell.com/send.php 而它应该仍然在 www.communicatingwell.com/contact.php 但从我可以在 Location 下看到的指向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>

发送.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");
}
?>
4

1 回答 1

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");
  }
?>
于 2013-11-06T22:51:45.267 回答