I'm trying to get my simple contact form to be functional. I want this form to either email me or record the contact data somewhere. I'm just now starting to learn PHP and Javascript -- so my knowledge is extremely limited.
The validation seems to be working (it will alert you if you don't put in a valid email, for example) -- but the form itself isn't being submitted anywhere.
When you enter information and click submit you'll get an ERROR 404 - Not Found (Then it references contact.php -- the php file I'm using) How can I start to troubleshoot this? Furthermore, if you have a clear, simple resource for learning about PHP and forms then I'd be more than happy to study more. I've searched (for a few hours) for decent tutorials but most don't provide clear explanations -- and just encourage you to copy and paste code.
<form role="form" id="contactform" form action="contact.php" method="post">
<div class="form-group">
<label for="name">Your Name</label>
<input type="text" class="form-control" id="name">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="subject">Subject</label>
<input type="subject" class="form-control" id="subject">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" id="message" rows="3"></textarea>
</div>
<button type="submit" class="btn">Submit</button>
<div id="msgSubmit" class="h3 text-center hidden">Message Submitted!</div>
</form>
---PHP---
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$EmailTo = "william@whatsauce.com";
$Subject = "New Message Received";
// prepare email body text
$Body .= "Name: ";
$Body .= $name;
$Body .= "
";
$Body .= "Email: ";
$Body .= $email;
$Body .= "
";
$Body .="Subject: ";
$Body .= $subject;
$Body .= "
";
$Body .= "Message: ";
$Body .= $message;
$Body .= "
";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success){
echo "success";
}else{
echo "invalid";
}
?>
Use a name attribute in your input fields. Only then you will be able to capture them values in your $_POST as a valid index, not through ids.