TestClear

Author Topic: PHP form not working on a template  (Read 3788 times)

Offline mcsmelinda

  • Supporter
  • **
  • Posts: 1
  • Karma: +0/-0
PHP form not working on a template
« on: October 31, 2011, 05:59:32 PM »

I downloaded a template for a website that I am building for a client. However, the contact form uses  a php file to send the info. I am new to .php and read through some basic tutorials and cannot find a syntax error.

Can someone review the code and see if they can see the error.

http://www.mcstemp.com/contact.htm  this is the actual temp webpage that I am testing it on.

Here is the code:

<?php

if(!$_POST) exit;

$email = $_POST['email'];


//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
]
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
   $error.="Invalid email address entered";
   $errors=1;
}
if($errors==1) echo $error;
else{
   $values = array ('name','email','message');
   $required = array('name','email','message');
   
   $your_email = "james@example.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!';
   }
}
?>



A website like falconconsultingandmarketing.com will provide you with the highest quality in the industry.

Offline janos

  • Contributor
  • *****
  • Posts: 53
  • Karma: +4/-0
Re: PHP form not working on a template
« Reply #1 on: November 03, 2011, 12:46:24 PM »
Quote
Parse error: syntax error, unexpected ']' in C:\wamp\www\index.php on line 9