Jump to content

syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING error


shwetapandit

Recommended Posts

i tried a lot bt can't get rid by parse error syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\sendmymail.php on line 19 in this prog if anyone suggest sol then it will be a great help for me.thanks in advance.my script is here:

 

 

 

<?php
 include 'subscriber_include.php';
 if (!$_POST) {
 //haven’t seen the form, so display it
 $display_block = <<<END_OF_BLOCK
 <form method="POST" action="$_SERVER[php_SELF]">

 <p><label for="subject">Subject:</label><br/>
 <input type="text" id="subject" name="subject" size="40" /></p>

 <p><label for="message">Mail Body:</label><br/>
 <textarea id="message" name="message" cols="50"
  rows="10"></textarea></p>
 <button type="submit" name="submit" value="submit">Submit</button>
 </form>
 END_OF_BLOCK;
 } else if ($_POST) {
 //want to send form, so check for required fields
 if (($_POST['subject'] == "") || ($_POST['message'] == "")) {
 header("Location:sendmymail.php");
 exit();
 }

 //connect to database
 doDB();

 if (mysqli_connect_errno()) {
 //if connection fails, stop script execution
 printf("Connect failed: %s\n", mysqli_connect_error());
 exit();
 } else {
 //otherwise, get emails from subscribers list
 $sql = "SELECT email FROM Subscribers_db";
 $result = mysqli_query($mysqli, $sql)
 or die(mysqli_error($mysqli));

 //create a From: mailheader
 $mailheaders = "From: Your Mailing List
 <[email protected]>";
 //loop through results and send mail
 while ($row = mysqli_fetch_array($result)) {
 set_time_limit(0);
 $email = $row['email'];
 mail("$email", stripslashes($_POST['subject']),
 stripslashes($_POST['message']), $mailheaders);
 $display_block .= "newsletter sent to: ".$email."<br/>";
 }
 mysqli_free_result($result);
 mysqli_close($mysqli);
 }
 }
 ?>
 <!DOCTYPE html>
 <html>
 <head>
 <title>Sending a Newsletter</title>
 </head>
 <body>
 <h1>Send a Newsletter</h1>
 <?php echo $display_block; ?>
 </body>
 </html>

commonly this comes from malformed heredoc statements - you can have NO whitespace on the line of the opening heredoc decleration after the name of the heredoc and you can have NO whitespace on the closing line of the heredoc before the heredoc name. Make absoloutly certain that there are no tabs or spaces on these lines that shouldn't be.

I coppied and ran the code above, I got the same massage about T_ENCAPSED_AND_WHITE SPACE - I then removed the white space at the start of the line "END_OF_BLOCK;" and it ran through fine.

 

hint: if someone gives you a suggestion - try following it up.

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.