#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    24
    Rep Power
    0

    HTML form to email


    I've been using a form I found online for a website in order to allow customers to contact the company by filling in the form and clicking submit.

    This form worked perfectly before however I've recently been re-writing the site into HTML5 and since I did this for the php file submitting the form no longer works.

    When I submit the form I get the following error:

    Parse error: syntax error, unexpected $end in /home/fhlinux203/d/designercurtains.biz/user/htdocs/flex/send_form_email.php on line 179.

    The file is located at www.designercurtains.biz/flex/send_form_email.php and the form is located at www.designercurtains.biz/flex/contact.html

    Your help is greatly appreciated!
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    The error is in the code (you're probably missing a }) but we can't help much if we can't see it.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    24
    Rep Power
    0
    How's this...

    PHP Code:
    <?php
    if(isset($_POST['email'])) {
         
        
    // EDIT THE 2 LINES BELOW AS REQUIRED
        
    $email_to "sue@designercurtains.biz";
        
    $email_subject "Designer Curtains Online Contact Form";
         
         
        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['first_name']) ||
            !isset(
    $_POST['last_name']) ||
            !isset(
    $_POST['email']) ||
            !isset(
    $_POST['telephone']) ||
            !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
        
    $last_name $_POST['last_name']; // required
        
    $email_from $_POST['email']; // not required
        
    $telephone $_POST['telephone']; // not 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 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($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 .= "First Name: ".clean_string($first_name)."\n";
        
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
        
    $email_message .= "Email: ".clean_string($email_from)."\n";
        
    $email_message .= "Telephone: ".clean_string($telephone)."\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);  
    ?>
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    there's no closing brace for the "if" statement.

    Use an IDE like Netbeans or Eclipse to avoid errors like that.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    24
    Rep Power
    0
    Sorry I have no understanding whatsoever of PHP - still trying to conquer HTML. Where should the closing brack go?
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    It's the closing brace to
    PHP Code:
    if(isset($_POST['email'])) { 
    So where do you think it should go?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Right at the very end before the ?> you should put a closing "}" brace.

    Using a decent editor can avoid these errors like has been mentioned.

    Take care,

    Leon.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    24
    Rep Power
    0
    Originally Posted by revillwebdesign
    Right at the very end before the ?> you should put a closing "}" brace.

    Using a decent editor can avoid these errors like has been mentioned.

    Take care,

    Leon.
    Excellent, that's got it working again. Strange as it worked before and I just copied and pasted that extract of code over from the previous version of the website.

    No matter, thanks for the help. As ever Devshed is an invaluable resource for annoying newbies like myself. I promise to research php when I'm more settled with HTML.

IMN logo majestic logo threadwatch logo seochat tools logo