Jump to content

Parse error: syntax error, unexpected T_SL in .... line 28


00stuff

Recommended Posts

I keep on getting this error but I can't figure out what's wrong. Line 28 is :

$stringData2 = <<<'EOF'

 

 

<?php

$stringData2 = <<<'EOF'
<?php
$name_first = $_POST['name_first'];
$name_last = $_POST['name_last'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message2 = 'First Name: " . $name_first . " \n Last Name: " . $name_last . " \n Phone: " . $phone . " \n Email: " . $email . "';
$to = '" . $receive_email . "';
$subject = 'Registration to " . $company_name . "';
$message = $message2;
$from = '" . $receive_email . "';
$headers = 'From:' . $from;
mail($to,$subject,$message,$headers);
echo 'Mail Sent. Click <a href="register.php">here</a> to go back!';
?>
EOF;

?>

 

Can someone help me please?

That is what everyone seems to think but when I put my typing cursor right after <<<'EOF' and press the delete key it just gives me <<<'EOF'<?php and then the rest of the code and that still gives me the same error. Do you think it could be something else?

I am running PHP version: PHP 5.2

 

I removed the single quotes and now I got this error:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/r/o/c/rochoa1/html/jssamples/register/index.php on line 30

 

 

this is the code:

 

$stringData2 = <<<EOF
<?php
$name_first = $_POST['name_first'];
$name_last = $_POST['name_last'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message2 = 'First Name: " . $name_first . " \n Last Name: " . $name_last . " \n Phone: " . $phone . " \n Email: " . $email . "';
$to = '" . $receive_email . "';
$subject = 'Registration to " . $company_name . "';
$message = $message2;
$from = '" . $receive_email . "';
$headers = 'From:' . $from;
mail($to,$subject,$message,$headers);
echo 'Mail Sent. Click <a href="register.php">here</a> to go back!';
?>
EOF;

 

line 30 is:

$name_first = $_POST['name_first'];

 

What is wrong now?

You need to escape any "$" you do not want to be parsed and arrays with associative indexes need be surrounded in {} if you want them to be parsed and not cause an error:

 

$stringData2 = <<<EOF
<?php
\$name_first = \$_POST['name_first'];
\$name_last = \$_POST['name_last'];
\$phone = \$_POST['phone'];
\$email = \$_POST['email'];
\$message2 = 'First Name: " . \$name_first . " \n Last Name: " . \$name_last . " \n Phone: " . \$phone . " \n Email: " . \$email . "';
\$to = '" . \$receive_email . "';
\$subject = 'Registration to " . \$company_name . "';
\$message = \$message2;
\$from = '" . \$receive_email . "';
\$headers = 'From:' . \$from;
mail(\$to,\$subject,\$message,\$headers);
echo 'Mail Sent. Click <a href="register.php">here</a> to go back!';
?>
EOF;

 

 

premiso, I think you are misunderstanding the syntax of the heredoc, if he does what you have suggested, none of his variables will be parsed...

 

OP, i think that you are receiving this error due to a concatenation error.. try using the complex syntax here

 

$stringData2 = <<<EOF
<?php
$name_first = {$_POST['name_first']};
$name_last = {$_POST['name_last']};
$phone = {$_POST['phone']};
$email = {$_POST['email']};
$message2 = 'First Name: " . $name_first . " \n Last Name: " . $name_last . " \n Phone: " . $phone . " \n Email: " . $email . "';
$to = '" . $receive_email . "';
$subject = 'Registration to " . $company_name . "';
$message = $message2;
$from = '" . $receive_email . "';
$headers = 'From:' . $from;
mail($to,$subject,$message,$headers);
echo 'Mail Sent. Click <a href="register.php">here</a> to go back!';
?>
EOF;

 

Also, in your first post you were using the nowdoc syntax, this was introduced as of PHP 5.3, since you are running PHP 5.2, this syntax will not work...

premiso, I think you are misunderstanding the syntax of the heredoc, if he does what you have suggested, none of his variables will be parsed...

 

AyKay, you might be mis-understanding his intentions. And no, I fully understand the heredoc syntax everything I wrote there was what I meant from my understanding. To me, it seems that he does not want the variables parsed, instead he wants a full php code to store in a file, IE write to file. Either or, I outlined how to fix it if that was not what he wanted with the  brackets {}. But yea, given the context, I do not think he wants the variables to be parsed. I could be wrong, but that is just how I took this code.

premiso, I think you are misunderstanding the syntax of the heredoc, if he does what you have suggested, none of his variables will be parsed...

 

AyKay, you might be mis-understanding his intentions. TO me, it seems that he does not want the variables parsed, instead he wants a full php code to store in a file, IE write to file. Either or, I outlined how to fix it if that was not what he wanted with the  brackets {}. But yea, given the context, I do not think he wants the variables to be parsed. I could be wrong, but that is just how I took this code.

true premiso, this sounds like a simple misunderstanding of what the OP wants..well at least we have provided him both ways to do it.... ;D

sorry if I came off as rude

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.