00stuff Posted July 14, 2011 Share Posted July 14, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/ Share on other sites More sharing options...
AyKay47 Posted July 14, 2011 Share Posted July 14, 2011 this is probably due to a space right after <<<'EOF' Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/#findComment-1242689 Share on other sites More sharing options...
00stuff Posted July 14, 2011 Author Share Posted July 14, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/#findComment-1242691 Share on other sites More sharing options...
PFMaBiSmAd Posted July 14, 2011 Share Posted July 14, 2011 There should be no single-quotes around the EOF Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/#findComment-1242693 Share on other sites More sharing options...
AyKay47 Posted July 14, 2011 Share Posted July 14, 2011 PFM, the singles quotes are for nowdoc syntax... OP, what PHP version are you running? Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/#findComment-1242704 Share on other sites More sharing options...
00stuff Posted July 14, 2011 Author Share Posted July 14, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/#findComment-1242735 Share on other sites More sharing options...
premiso Posted July 14, 2011 Share Posted July 14, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/#findComment-1242738 Share on other sites More sharing options...
AyKay47 Posted July 14, 2011 Share Posted July 14, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/#findComment-1242745 Share on other sites More sharing options...
premiso Posted July 14, 2011 Share Posted July 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/#findComment-1242747 Share on other sites More sharing options...
AyKay47 Posted July 14, 2011 Share Posted July 14, 2011 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.... sorry if I came off as rude Quote Link to comment https://forums.phpfreaks.com/topic/241981-parse-error-syntax-error-unexpected-t_sl-in-line-28/#findComment-1242749 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.