Home PHP Undefined variable for HTML Form
Reply: 0

PHP Undefined variable for HTML Form

user2715
1#
user2715 Published in July 23, 2018, 1:34 pm

This question already has an answer here:

  • PHP: “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” 26 answers

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);
?>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.590614 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO