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
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Parse error - T_CONSTANT_ENCAPSED_STRING

    Hi all, I keep getting this error i someones got a minute to check out this contact form script

    PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on line 37

    Line 37:

    Code:
    Address:	'.$Address'

    Code:
    <?php
    
    
    // get posted data into local variables
    $EmailFrom = "contact@email.com";
    $EmailTo = "contact@email.com";
    $Subject = "Inquiry from website.com";
    $Name = $_POST['Name']; 
    $Address = $_POST['Address']; 
    $City = $_POST['City']; 
    $State = $_POST['State']; 
    $Zip = $_POST['Zip']; 
    $Phone = $_POST['Phone']; 
    $email = $_POST['email']; 
    $contactBy = $_POST['contactBy'];
    $bestTimeToCall = $_POST['bestTimeToCall']; 
    $comments = $_POST['comments'];
    
    
    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    
    
    $headers  = "From: website.com <contact@email.com>\r\n";
    $headers .= "Reply-To: ".$Name." <".$email.">\r\n";
    $headers .= "Return-Path: ".$Name." <".$email.">\r\n";
    
    // prepare email body text
    
    $body=		'
    
    Name:		'.$Name'
    Address:	'.$Address'
    City:		'.$City;'
    State:		'.$State'
    Zip:		'.Zip'
    Phone:		'.$Phone'
    Email:		'.$email'
    Contact by:	'.$ContactBy'
    Best Time:	'.$bestTimeToCall'
    Comments:	'.$comments'
    
    ';
    
    // send email 
    $success = mail($EmailTo, $body, $headers); 
    
    // redirect to success page 
    if ($success){
    	print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_success.html\">";
    }
    else{
    	print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.html\">";
    }
    ?>
    Thank you

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    52
    Thanks
    4
    Thanked 6 Times in 6 Posts
    I would try it using the standard method for multi-line strings:

    PHP Code:
    $body = <<<EOS
    Name:    $Name
    Address:    $Address
    City:        $City
    State:    $State
    Zip:        $Zip
    Phone:    $Phone
    Email:    $email
    Contact by:$ContactBy
    Best Time:    $bestTimeToCall
    Comments:    $comments
    EOS; 
    Last edited by cmancone; 03-13-2009 at 03:32 AM.

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    52
    Thanks
    4
    Thanked 6 Times in 6 Posts
    I should explain more. You stick some identifying code after the '<<<'. In this case, that code was 'EOS'. It could have been whatever you wanted. Everything that occurs between <<<EOS and EOS; is taken as a string surrounded by double quotes, so variables will be interpreted normally. The most vital part is that the ending bit, 'EOS;' Must be on a line by itself. Nothing else can be on the line, either before it or after it. Otherwise it won't work. I want to make this clear, since the php code block insists on putting two spaces after the EOS; So if you copied and pasted my example into a php file and didn't get rid of those spaces after EOS;, then you would still get a parse error.

    Php doesn't support multi-line strings otherwise, so what you were trying will only work this way.

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, thanks so much, that cleared the error!
    Last edited by theflyingminstr; 03-13-2009 at 05:12 AM.

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Please post all of your updated code.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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