Hi, I have a contact page with a contact form that posts to my contact.php but when I test and submit it via the website I get this "Error!"
below is my form
<form action="contact.php" method="post" id="contactform">
<ol>
<li>
<label for="name">First Name <span class="red">*</span></label>
<input id="name" name="name" class="text" />
</li>
<li>
<label for="email">Your email <span class="red">*</span></label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="company">Contact No.</label>
<input id="company" name="company" class="text" />
</li>
<li>
<label for="subject">Subject</label>
<input id="subject" name="subject" class="text" />
</li>
<li>
<label for="message">Message <span class="red">*</span></label>
<textarea id="message" name="message" rows="6" cols="50"></textarea>
</li>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" />
</li>
</ol>
</form>
below is the contact.php
<?php
if(!$_POST) exit;
$email = $_POST['email'];
if (!preg_match('/[a-z0-9!#$%&\'*+\/=?\^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?\^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/', $email)) {
$error.="Invalid email address entered";
$errors=1;
} else {
// email is ok!
}
if (!empty($errors))
{
if ($errors==1) echo $error;
}
else{
$values = array ('name','email','message');
$required = array('name','email','message');
$your_email = "mail@steve-berrill.com";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\n";
foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'company') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
}
if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>
Please help me I know its probably something small but I just cant seem to fix it