我有一个简单的联系表格,它会抛出一个
“注意:未定义的索引:e在第24行的\ 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.');}
?>
答案 0 :(得分:1)
看起来它与e
get参数有关。发送电子邮件后,您可以将用户重定向到某个网址,例如http://yourhost/com/somepage?e=Error+text
因此,您收到的通知似乎与您显示状态消息的位置有关。您应该在那里进行检查(默认情况下,您的查询字符串中没有e
):
if (isset($_GET['e'])) {
//output message
}
答案 1 :(得分:0)
在您阅读$_GET['e']
参数的位置,您应首先检查它是否与isset
一起显示:
if (isset($_GET['e'])) {
// show the message to user
}
答案 2 :(得分:0)
这不是错误,而是注意这是真的不同。
如果未设置$ _SERVER ['HTTP_REFERER'],您将收到此通知。
您应该添加if(isset($_SERVER['HTTP_REFERER']))
。
尝试以下
if (isset($_POST['name']) AND isset($_SERVER['HTTP_REFERER'])) {