De errors die ik krijg:
Notice: Undefined index: submit in C:\xampp\htdocs\ContactForm\Index.php on line 2
Notice: Undefined variable: error in C:\xampp\htdocs\ContactForm\Index.php on line 38
Notice: Undefined variable: sent in C:\xampp\htdocs\ContactForm\Index.php on line 40
<?php
if($_POST['submit']) {
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments']))
{
$error = true;
} else {
$to = "[email protected]";
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$comments = trim($_POST['comments']);
$subject = "Contact Form";
$messages ="Name: $name \r\n Email: $email \r\n Comments: $comments";
$headers = "From:" . $name;
$mailsent = mail($to,$subject,$messages,$headers);
if($mailsent)
{
$sent = true;
}
}
}
?>
<html>
<head>
<title>Contact</title>
</head>
<body>
<h1>Stefan's Contact Form</h1>
<?php if($error == true) { ?>
<p class="error"> Er is een veld niet ingevuld. </p>
<?php } if($sent == true) { ?>
<p class="sent"> Uw mail is verstuurd.</p>
<?php } ?>
<form name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label for="name"> Name: </label>
<input type="text" name="name">
<label for="email"> Email: </label>
<input type="email" name="email">
<textarea name="comments" cols="15" rows="10"></textarea>
<input type="submit" name="submit" class="submit" value="Submit"/>
</form>
</body>
</html>