0

I'm no programmer. I Googled and checked related Stack Overflow 'Parse error' posts. I counted all my brackets. I played with semicolons in case one was missing in the template. I don't have the knowledge to understand what's missing from the code. Apologies since I've read how much these questions are disliked, but I'd really love the help.

Full Error:

Parse error: syntax error, unexpected '}' in /home/thesmash/public_html/html_form_send.php on line 24

Line 24:

}

PHP EDIT- let's try this again

<?php
if(isset($_POST['email'])) {


$email_to = "contact@thesmash.ca";

$email_subject = "Inquiry from Website";


function died($error) {
// error code
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['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments']))  {
died('We are sorry, but there appears to be a problem with the form you submitted.');       
}

$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 if(!preg_match($email_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 name you entered does not appear to be valid.<br />';
     }
      if(strlen($comments) < 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 .= "Name: ".clean_string($first_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\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 your interest in pursing a creative art class! We will be in touch     with you very soon.

<?php

die();
?>
Nick
  • 1
  • 3
  • 2
    Add some sensible code indentation and it will be **obvious** – RiggsFolly Aug 25 '15 at 01:03
  • 1
    Where is line 24 in your actual code? In your current code `if(isset($_POST['email'])) {` isn't closed. Also indent your code, it will make it much easier to read. – chris85 Aug 25 '15 at 01:03
  • I honestly don't know what's common for code indentation, this is just how I got the code. – Nick Aug 25 '15 at 01:05
  • @chris85 Line 24 is after `died('We are sorry, but there appears to be a problem with the form you submitted.');       }` – Nick Aug 25 '15 at 01:07
  • There isn't a reference I know of on the PHP site for indentation because it isn't "wrong", just hard to read. Here's a PEAR doc on it, https://pear.php.net/manual/en/standards.control.php. – chris85 Aug 25 '15 at 01:10
  • The error I get is `Parse error: parse error...on line 28` which is because of the non-closing first `isset` see first comment. eval.in agrees, https://eval.in/421681. So either this isn't your exact code or your PHP version has some issues.. – chris85 Aug 25 '15 at 01:13
  • @chris85 Ah, just realized what you were saying: Line 2's { closes at the end of the php, past where I posted. Thanks for the doc on indentation. I checked and my actual code does have indents, but I guess they don't copy over? – Nick Aug 25 '15 at 01:15
  • Issue doesn't reproduce. Close the `isset` in the eval example and run it. I've run locally same result which differs from yours. – chris85 Aug 25 '15 at 01:17
  • @chris85 Problem was I didn't give you the full code. Edited it in. – Nick Aug 25 '15 at 01:31
  • That code works fine. https://eval.in/421684 Test first then when you have a producible example post...or better run through the steps listed on the other question/answer and see if you can debug it. – chris85 Aug 25 '15 at 01:33

0 Answers0