0

I have put together a email form but for some reason i am getting the following errors.

Notice: Undefined index: email in /home/furniss11/public_html/sendform.php on line 7

Notice: Undefined index: name in /home/furniss11/public_html/sendform.php on line 8

Notice: Undefined index: message in /home/furniss11/public_html/sendform.php on line 9

Notice: Undefined index: message in /home/furniss11/public_html/sendform.php on line 12

Notice: Undefined index: message in /home/furniss11/public_html/sendform.php on line 13

I cant seem to find what i have done wrong here.

Here is the HTML

<form id="form" method="POST" action="sendform.php">
      <p class="name">
        <input type="text" name="name" id="name" placeholder="Enter Name Here"/>
        <label for="name"> Name: </label>
     </p>

     <p class="email">
        <input type="email" name="email" id="email" placeholder="Enter Email Here"/>
        <label for="email"> Email Address: </label>
     </p>

     <p class="message">
        <textarea id="message" name="message" rows="6"> </textarea>
        <label for="message"> Message: </label>
     </p>

        <p class="submit">
     <input type="submit" name="submit"  value="SEND" id="submit"/>
     </p>
</form>

and here is the PHP

$recipients = "*****";
$to = $recipients; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$message = $_POST['message'];
$subject = "Web-Development Hub Feedback";
$subject2 = "Copy of your feedback";
$message = $name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender;
echo $name;

Can someone explain why i am getting undefined variables?

Many thanks

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • 1
    Use if isset $_POST['submit'] and in this condition put all your PHP code from the question. See if it works when you submit the form. – Ionut Necula Jul 14 '16 at 14:48
  • Looks like the form values do not get transmitted, at least not as post parameters. Might be that the form gets submitted by a javascript routine, not by the browser internal logic itself. You have to check what is submitted, dump `$_GET` and `$_POST` once. – arkascha Jul 14 '16 at 14:49
  • 1
    Betting the PHP and HTML are all in the same file: when you load the page the first time you have not set the `$_POST` array. You need to check for submission of the form. – Jay Blanchard Jul 14 '16 at 14:49
  • different files jay. – Jack Furniss Jul 14 '16 at 14:56
  • I orginally had isset in my code, that removes the error but thats pointless as the email gets sent with empty information – Jack Furniss Jul 14 '16 at 14:56

0 Answers0