-2

I am trying to run a contact form PHP script and HTML form and when I run it I get the following errors.

Notice: Undefined variable: name in /storage/ssd4/333/4197333/public_html/heros51/confirm.php on line 17

Notice: Undefined variable: p in /storage/ssd4/333/4197333/public_html/heros51/confirm.php on line 18

Notice: Undefined variable: message in /storage/ssd4/333/4197333/public_html/heros51/confirm.php on line 18

Notice: Undefined variable: visitor_email in /storage/ssd4/333/4197333/public_html/heros51/confirm.php on line 21

<form action="confirm.php" method="POST" >
        <label>Name >></label><input id="name" type="text" /><br />
        <label>Email >></label><input id="email" type="text" /><br />
        <label>PRI >></label><input id="p" type="text" /><br />
        <label>Message >></label><textarea id="message" rows="1"></textarea><br /><br /><br />
        <input type="submit" value="submit" />
        <a class="button" alt="" href="index.html">Cancel</a>
    </form>

The PHP which is linked looks like this:

if( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['p']) && isset($_POST['message']) ){
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$p = $_POST['p'];
$email_from = 'default03@securemail.com';
$email_subject = "New Form submission $name ";
$email_body = "You have received a new message from the user $p.\n".  "Here is the message:\n $message".
$to = "erixom@gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
}
else
echo " ISSET FAIL";
$email_from = 'default03@securemail.com';
$email_subject = "New Form submission $name ";
$email_body = "You have received a new message from the user $p.\n".  "Here is the message:\n $message".
$to = "test@gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
Community
  • 1
  • 1

1 Answers1

2

instead of id="name" you must use name="name". The id attribute is used for JavaScript manipulation while the name attribute is used to name your POST variables

I would like to add that you should sanitize user submitted inputs. Even tho this might not be a internet facing project, it's never too early too adopt this as a habbit :)

hexYeah
  • 1,040
  • 2
  • 14
  • 24