Hello everyone,
I am building a website for a club at my University and I just need some help with making this contact form work. Would you please check my HTML code for the contact form to see if it has been coded properly and then check to see if the contact.php code is correct. My main goal besides making this function work is also to provide users with an error message saying that their mail was sent unsuccesfully if they do not fill out the required fields and fill out the proper number for the anti-spam measure.
My website is www.bcsa.tk. if you scroll to the bottom that is how the contact form looks like if you need any sort of clarifiication.
Here is the contact form code:
<!-- ContactForm -->
<div id="ContactForm">
<div id="message"></div>
<form method="post" action="contact.php" id="contactform">
<fieldset>
<legend>ContactForm</legend>
<label for="name" accesskey="U">Your Name: <span class="required">*</span></label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="email" accesskey="E">Your Email: <span class="required">*</span></label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="comments" accesskey="C">Your Message: <span class="required">*</span></label>
<textarea name="comments" cols="120" rows="11" id="comments"></textarea>
<br />
<label for="verify" accesskey="V">3 + 1 = <span class="required">*</span></label>
<input name="verify" type="text" id="verify" size="3" value="" style="width: 30px;" /><input type="submit" class="submit" id="submit" value="Submit" />
</fieldset>
</form>
</div>
<!-- /ContactForm -->
And here is the conact.php code:
<?php
if(isset($_POST['submit'])) {
$to = "example@example.com";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
Thank you all for your help.