I want to make a contact form which I have done in HTML like this.
none of this matters i found a better way to handle this using $_SERVER["RESQUEST_METHOD"]
I'll leave it up in case anyone is as new as me and making stupid mistakes.
<!DOCTYPE html>
<html lang="en">
<body>
<h4>Contact me!</h4>
<form method="post" action="test_form.php" autocomplete="on">
Subject:
<br>
<input type="text" name="subject" required>
<br>name:
<br>
<input type="text" name="name" required>
<br>Email:
<br>
<input type="email" name="email" required>
<br>Message:
<br>
<textarea name="message" rows="5" maxlength="500"></textarea>
<br>
<input type="submit" name="submit">
</form>
</body>
</html>
then after I add in the PHP to a separate form called test_form.php
this is where I am stuck I have gone over three different layouts and formats what not and still returning the fatal error. this is my .php file I apologise for the layout. (just to add I have tried it with my variables inside the isset and I have tried them after.
<?php
$submit = $_post['submit'];
$to = "no@way.co.uk";
$header = "From:$name Email:$email /n subject:$subject";
$formcontent = "Name:$name /n Message:$message";
if (isset('submit')){
if (empty($_post['subject'])){
$subjectErr = "Subject is required!"
}else{
$subject = valid ($_post['subject']);
}
if(empty($_post['name'])){
$nameErr = "Name is required!";
}else{
$name = valid ($_post ['name']);
}
if(empty($_post['email'])){
emailErr = "Email is required!";
}else{
$email = valid ($_post['email']);
}
if(empty($_post['message'])){
$message = "";
}else{
$message = valid ($_post['message']);
}
//function to validate data
function valid ($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
mail ($to, $subject, $formcontent, $header) or die ('error');
echo "thank you";
}
?>
My question is where am I going wrong? I haven't even finished it yet I was just testing it to see if it was working.