Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
557 views
in Q2A Core by

Hello everyone, I am new to php and i am building an action page for a HTML register page but i keep getting the below error:

Parse error: syntax error, unexpected $end in /home/content/24/11465124/html/contact.php on line 102.

Please, I need help, here are the codes below:

 

<?php
 
 if(isset($_POST['email_address'])){
     
    // CHANGE THE TWO LINES BELOW
    $email_to = 'teddy@yahoo.com';
     
    $email_subject = "Training Details";
     
function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    
   }
    
     
    // validation expected data exists
    if(!isset($_POST['timing']) ||
        !isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['company']) ||
        !isset($_POST['address']) ||
        !isset($_POST['city']) ||
        !isset($_POST['training_type']) ||
        !isset($_POST['state']) ||
        !isset($_POST['zip_code']) ||
        !isset($_POST['phone']) ||
        !isset($_POST['email_address']) ||
        !isset($_POST['comment'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }
     
    $timing = $_POST['timing']; // required
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $company = $_POST['company']; // required
    $address = $_POST['address']; // required
    $city = $_POST['city']; // required
    $training_type = $_POST['training_type']; // required
    $state = $_POST['state']; // required
    $zip_code = $_POST['zip_code']; // required
    $phone = $_POST['phone']; // not required
    $email_from = $_POST['email_address']; // required
    $comment = $_POST['comment']; // required
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_address_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comment) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
    
    $email_message .= "Timing: ".radio($timing)."\n";
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Company: ".clean_string($company)."\n";
    $email_message .= "Address: ".clean_string($address)."\n";
    $email_message .= "City: ".clean_string($city)."\n";
    $email_message .= "Training Type: ".clean_string($training_type)."\n";
    $email_message .= "State: ".clean_string($state)."\n";
    $email_message .= "Zip code: ".clean_string($zip_code)."\n";
    $email_message .= "Phone No: ".clean_string($phone)."\n";
    $email_message .= "Email Address: ".clean_string($email_from)."\n";
    $email_message .= "Comments: ".clean_string($comment)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

<!-- place your own success html below -->
 
Thank you for contacting <a href="mailto:teddy@yahoo.com">Teddy Training Department</a>. We will be in touch with you very soon.
 
<?php
die();
?>

1 Answer

0 votes
by

Hi

Move your functions outside the if statement.

Add the missing closing brace.

 

 

<?php
 
function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    
   }



    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }







 if(isset($_POST['email_address'])){
     
    // CHANGE THE TWO LINES BELOW
    $email_to = 'teddy@yahoo.com';
     
    $email_subject = "Training Details";
     

    
     
    // validation expected data exists
    if(!isset($_POST['timing']) ||
        !isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['company']) ||
        !isset($_POST['address']) ||
        !isset($_POST['city']) ||
        !isset($_POST['training_type']) ||
        !isset($_POST['state']) ||
        !isset($_POST['zip_code']) ||
        !isset($_POST['phone']) ||
        !isset($_POST['email_address']) ||
        !isset($_POST['comment'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }
     
    $timing = $_POST['timing']; // required
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $company = $_POST['company']; // required
    $address = $_POST['address']; // required
    $city = $_POST['city']; // required
    $training_type = $_POST['training_type']; // required
    $state = $_POST['state']; // required
    $zip_code = $_POST['zip_code']; // required
    $phone = $_POST['phone']; // not required
    $email_from = $_POST['email_address']; // required
    $comment = $_POST['comment']; // required
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_address_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comment) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     

    
    $email_message .= "Timing: ".radio($timing)."\n";
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Company: ".clean_string($company)."\n";
    $email_message .= "Address: ".clean_string($address)."\n";
    $email_message .= "City: ".clean_string($city)."\n";
    $email_message .= "Training Type: ".clean_string($training_type)."\n";
    $email_message .= "State: ".clean_string($state)."\n";
    $email_message .= "Zip code: ".clean_string($zip_code)."\n";
    $email_message .= "Phone No: ".clean_string($phone)."\n";
    $email_message .= "Email Address: ".clean_string($email_from)."\n";
    $email_message .= "Comments: ".clean_string($comment)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

<!-- place your own success html below -->
 
Thank you for contacting <a href="mailto:teddy@yahoo.com">Teddy Training Department</a>. We will be in touch with you very soon.
 
<?php

}


die();
?>

 

Monty and Bex

Welcome to the Q&A site for Question2Answer.

If you have a question about Q2A, please ask here, in English.

To report a bug, please create a new issue on Github or ask a question here with the bug tag.

If you just want to try Q2A, please use the demo site.

Categories

...