Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with contact form

    Hi all, when posting my contact form I get this error:
    Parse error: syntax error, unexpected T_STRING in /home/friddbui/public_html/Assets/contactengine.php on line 38
    I'm not sure what the problem is. Perhaps I've incorrectly written where I'm wanting to direct then once they've submitted the contact form.
    Could somebody please help. Here's a link to my contact page
    http://www.friddbuilding.co.nz/contact.html

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    That html link doesn't help as the error is in your PHP.

    unexpected T_STRING usually (for me) indicates a misplaced comma or bracket.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is my contact form php

    PHP Code:
    <?php

    $EmailFrom 
    "chriscoyier@gmail.com";
    $EmailTo "a.harper@xtra.co.nz";
    $Subject "Website enquiry";
    $Name Trim(stripslashes($_POST['Name'])); 
    $Tel Trim(stripslashes($_POST['Tel'])); 
    $Email Trim(stripslashes($_POST['Email'])); 
    $Message Trim(stripslashes($_POST['Message'])); 

    // validation
    $validationOK=true;
    if (!
    $validationOK) {
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }

    // prepare email body text
    $Body "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";

    // send email 
    $success mail($EmailTo$Subject$Body"From: <$EmailFrom>");

    // redirect to success page 
    if ($success){
      print 
    "<meta http-equiv=\"refresh\" content="http://www.friddbuilding.co.nz/contactsuccess.html">";
    }
    else{
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    PHP Code:
    print "<meta http-equiv=\"refresh\" content=\"0;URL='http://www.friddbuilding.co.nz/contactsuccess.html'\">"
    You could have corrected this by comparing it to your other examples

    meta, refresh is a legacy method and use of header() to re-direct is preferred.

    BTW All that '$Body .=' is inefficient/a little messy - it could be constructed in fewer lines:

    PHP Code:
    $Body "Name: $Name\n"// etc.
    $Body .= "Tel: $Tel\n"
    or one or two bigger lines.

    Added: And you should remove, or use fake, email addresses in your posted-code.
    Last edited by AndrewGSW; 08-05-2012 at 10:17 PM. Reason: Added apostrophes to expression
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,476
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by lesh View Post
    PHP Code:
      print "<meta http-equiv=\"refresh\" content="http:// 
    That last " before http:// should be escaped. The http:// is the unexpected T_STRING while everything after the // is a comment. If you look at your code in an editor like notepad++ you will see this because the colours change around those parts of that line of code.

    Quote Originally Posted by lesh View Post
    PHP Code:
    $Body "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n"
    Quote Originally Posted by AndrewGSW View Post
    BTW All that '$Body .=' is inefficient/a little messy - it could be constructed in fewer lines:

    PHP Code:
    $Body "Name: $Name\n"// etc.
    $Body .= "Tel: $Tel\n"
    Thats still messy. The heredoc would be far better for this:
    PHP Code:
    $Body = <<< STOP

    Name: $Name
    Tel: $Tel
    Etc: $Etc

    STOP; 
    $Body will then hold a variable that looks exactly like the text there with the variables replaced with their values and the lines / carriage returns preserved.
    I can't really think of anything to write here now...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •