2012-01-25 75 views
0

我有一個簡單接觸形式這就是投擲一個PHP未定義索引錯誤?

「通知:未定義索引:E在\ nas43ent \域\米\ mysite.co.uk \上線路24用戶\ htdocs中\接觸us.php」

錯誤,我似乎無法看到爲什麼,但因爲我的語法看起來正確?

<?php 

$name = $_POST['name']; 
$email = $_POST['email']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 
$to = "[email protected]"; 

    //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.');} 

?> 
+2

請粘貼實際源,第24行是註釋 – sathia

+0

您確定要使用$ _ SERVER [ 'HTTP_REFERER']? 'e'指的是你在這裏的任何地方都不粘貼的$ _GET ['e']嗎? –

回答

1

看起來是關係到e GET參數。在發送電子郵件後,您將用戶重定向到http://yourhost/com/somepage?e=Error+text

因此您收到的通知似乎與您顯示狀態消息的地點有關。你應該把檢查存在(因爲默認情況下你不必在你的查詢字符串e):

if (isset($_GET['e'])) { 
    //output message 
} 
0

在的地方,你看$_GET['e']放慢參數,你應該首先檢查它是否存在與isset

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

這是不是一個錯誤,但通知,這實在是不同的。

如果未設置$ _SERVER ['HTTP_REFERER'],您將收到此通知。您需要添加if(isset($_SERVER['HTTP_REFERER']))

請嘗試以下

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