Skip navigation
Currently Being Moderated

PHP form submission Problem

Aug 10, 2012 2:46 AM

Dear all,

PHP enquiry form submission some error is comes

"Parse error: syntax error, unexpected T_STRING in /home/newtocli/public_html/en45/send_form_email.php on line 11"

Please help me

WEBLINK

 

 

PHP goes like this

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>PHP Form</title>

</head>

 

 

<body><?php

if(isset($_POST['email'])) {

 

    // EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to = "xyz@xyz.co.in";

    $email_subject = "Your email subject line";

 

 

    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['email']) ||

        !isset($_POST['telephone']) ||

                    !isset($_POST['company_name']) ||

        !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

    $telephone = $_POST['telephone']; // not required

          $last_name = $_POST['company_name']; // 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,$company_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 .= "Email: ".clean_string($email_from)."\n";

    $email_message .= "Telephone: ".clean_string($telephone)."\n";

          $email_message .= "Company Name: ".clean_string($company_name)."\n";

    $email_message .= "Comments: ".clean_string($comments)."\n";

 

/* Redirect visitor to the thank you page */

header('Location:gt.html');

exit();

 

// 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); 

?>

 

<!-- include your own success html here -->

 

Thank you for contacting us. We will be in touch with you very soon.

 

<?php

}

?>

</body>

</html>

 
Replies
  • Currently Being Moderated
    Aug 10, 2012 4:20 AM   in reply to manojb05

    2 issues manojb

     

     

    1) You have $last_name instead of $company_name in your php script (should be as below)

     

    $company_name = $_POST['company_name']; // required

     

     

    2) If you position the redirect where you have the form will not send the information as the php stops running at that point and never gets to the @mail command

     

    /* Redirect visitor to the thank you page */

     

    header('Location:gt.html');

     

    exit();

     

    Position it AFTER the @mail command.

     

     

    Also the php script doesnt need the html wrapped around it. It can just go in a document without that.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 10, 2012 5:20 AM   in reply to manojb05

    Have your removed the html tags from around the form script?

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>PHP Form</title>

    </head>

     

     

    <body>

     

     

     

     

    </body>

    </html>

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 10, 2012 5:41 AM   in reply to osgood_

    If the form works you can turn error reporting off - just add the below after the opening <?php tag

     

    error_reporting(0);

     

    The form works ok for me.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 10, 2012 6:07 AM   in reply to manojb05

    You still have not removed the html code from around the php script...try removing that.

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>PHP Form</title>

    </head>

     

     

    <body>

     

     

     

     

    </body>

    </html>

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 10, 2012 6:17 AM   in reply to manojb05

    Yes,

     

    I don't know why you are getting the T_String error. If I copy what you paste and test it with your form everything works fine for me.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 10, 2012 7:12 AM   in reply to manojb05

    What was it saved as before then manojb?

     

    Your form action says:

     

    send_form_email.php

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points