Jump to content

I get error when running my contact form via php script


kingberrill

Recommended Posts

hi all, I have a a booking form which works just like a contact form but I am getting "error" when I send the message

 

below is the 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>

 

and here is the contract script (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 = "[email protected]";
$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!';
}
}
?>

 

feel free to use the contact form on the site www.mossfarmcattery.co.uk

 

[attachment deleted by admin]

kingberrill,

 

I down-loaded your html and php script, and I get : Message sent!.

 

Somthing is wrong with you OS sendmail system.

 

Scot L. Diddle, Richmond VA

ok, I think i know wots wrong, the site is not hosted with me at the moment so maybe hes the other hosts problem because I have a script the same on another site and its fine so Ill just have to wait till the domain is on my hosting, thanks guys :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.