View Full Version : PHP Parse error - T_CONSTANT_ENCAPSED_STRING

03-13-2009, 01:50 AM
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:

Address: '.$Address'


// 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
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";

$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\">";
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_error.html\">";

Thank you

03-13-2009, 03:28 AM
I would try it using the standard method for multi-line strings:

$body = <<<EOS
Name: $Name
Address: $Address
City: $City
State: $State
Zip: $Zip
Phone: $Phone
Email: $email
Contact by:$ContactBy
Best Time: $bestTimeToCall
Comments: $comments

03-13-2009, 03:32 AM
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.

03-13-2009, 04:51 AM
Hi, thanks so much, that cleared the error!

03-13-2009, 05:13 AM
Please post all of your updated code.