PHP未定义索引错误?

PHP未定义索引错误?,php,Php,我有一个简单的联系方式,就是抛出一个 “注意:第24行的未定义索引:e in\nas43ent\Domains\m\mysite.co.uk\user\htdocs\contact-us.php” 错误,我似乎不明白为什么我的语法看起来正确 <?php $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $to = "d

我有一个简单的联系方式,就是抛出一个

“注意:第24行的未定义索引:e in\nas43ent\Domains\m\mysite.co.uk\user\htdocs\contact-us.php”

错误,我似乎不明白为什么我的语法看起来正确

<?php 

$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "dave@.co.uk";

    //begin of HTML message
    $message = "
  From : $name,
  Email: $email,
  Subject: $subject,
  Message: $message ";
   //end of message

    // To send the HTML mail we need to set the Content-type header.
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers  .= "From: Website Enquiry";


if (isset($_POST['name'])) {
       // now lets send the email.
   mail($to, $subject, $message, $headers);

header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=Thankyou, we will be in touch shortly.');

} else {header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=There was an error sending your message, Please try again.');}

?> 

在您阅读
$\u GET['e']
参数的地方,您应该首先检查它是否与
isset一起出现:

if (isset($_GET['e'])) {
    // show the message to user
}

这不是一个错误,而是一个注意事项,这是真正不同的

如果未设置$\u服务器['HTTP\u REFERER'],您将收到此通知

您应该添加
if(isset($\u SERVER['HTTP\u REFERER'])

试试下面的方法

if (isset($_POST['name']) AND isset($_SERVER['HTTP_REFERER'])) {

看起来它与
e
get参数相关。发送电子邮件后,您将用户重定向到某个url,如

因此,您收到的通知似乎与您显示状态消息的位置有关。您应该将check放在那里(默认情况下,查询字符串中没有
e
):


请粘贴实际源代码,第24行是注释。是否确实要使用$\u服务器['HTTP\u REFERER']?“e”是指您没有粘贴到此处的某个位置的$\u GET['e']吗?
if (isset($_GET['e'])) {
    //output message 
}