0

I have a simple contact form thats throwing up an

"Notice: Undefined index: e in \nas43ent\Domains\m\mysite.co.uk\user\htdocs\contact-us.php on line 24"

error, I cant seem to see why however as my syntax looks correct?

<?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
  • 2
    please, paste the actual source, line 24 is a comment Commented Jan 25, 2012 at 10:35
  • Are you sure you want to use $_SERVER['HTTP_REFERER'] ? Does 'e' refers to some $_GET['e'] you didn't paste anywhere here? Commented Jan 25, 2012 at 10:36

3 Answers 3

1

Looks like it is related to e get parameter. After sending email you redirect user to some url like http://yourhost/com/somepage?e=Error+text

So the notice you get seems to be related to the place you display status message. You should put check there (as by default you don't have e in your query string):

if (isset($_GET['e'])) {
    //output message 
}
Sign up to request clarification or add additional context in comments.

Comments

0

In place where you read $_GET['e'] paramter you should first check if it's present with isset:

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

Comments

0

This is not an error but a NOTICE this is really different.

If $_SERVER['HTTP_REFERER'] is not set, you will receive this notice.

You should add if(isset($_SERVER['HTTP_REFERER'])).

Try the following

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.