Page 1 of 1

HELP! Parse error: syntax error, unexpected T_STRING in....

Posted: Sun Jan 31, 2010 1:00 pm
by dek
Hi,
Im having trouble putting a contact form into my website.
I copied a "simple" PHP code from a website, which gives away the code for free for anyone without experience to use (me), to create a contact form and there is a problem with it which i can't work out.
The code appears to be fine but im getting this message:

Parse error: syntax error, unexpected T_STRING in /mnt/w0604/d30/s07/b030da52/www/contact_me/contactme.php on line 15

Here is the code in question. Can someone here have a look and tell me what is wrong with it? Your experience and expertise in PHP matters is greatly appreciated.I have highlited the code in question, Line 15, in red. Here is the code:



<table width="760" border="0" cellspacing="10" cellpadding="0" align="center">
<tr>
<td align="center">

<?php
if (isset($_POST["op"]) && ($_POST["op"]=="send")) {

/******** START OF CONFIG SECTION *******/
$sendto = "nickedwards@tailoredpersonaltraining.co.uk";
$subject = "Website Contact Enquiry";
// Select if you want to check form for standard spam text
$SpamCheck = "Y"; // Y or N
$SpamReplaceText = "*content removed*";
// Error message printed if spam form attack found
$SpamErrorMessage = "<p align="center"><font color="red">Malicious code content detected.</font><br><b> Your IP Number of </b>".getenv("REMOTE_ADDR")."<b> has been logged.</b></p>";
/******** END OF CONFIG SECTION *******/

$name = $HTTP_POST_VARS['name'];
$email = $HTTP_POST_VARS['email'];
$message = $HTTP_POST_VARS['message'];
$headers = "From: $emailn";
$headers . "MIME-Version: 1.0n"
. "Content-Transfer-Encoding: 7bitn"
. "Content-type: text/html; charset = "iso-8859-1";nn";
if ($SpamCheck == "Y") {
// Check for Website URL's in the form input boxes as if we block website URLs from the form,
// then this will stop the spammers wastignt ime sending emails
if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();}
if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();}

// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer
$pattern = '/(;|||`|>|<|&|^|"|'."n|r|'".'|{|}|[|]|)|()/i'; // build the pattern match string

$name = preg_replace($pattern, "", $name);
$email = preg_replace($pattern, "", $email);
$message = preg_replace($pattern, "", $message);

// Check for the injected headers from the spammer attempt
// This will replace the injection attempt text with the string you have set in the above config section
$find = array("/bcc:/i","/Content-Type:/i","/cc:/i","/to:/i");
$email = preg_replace($find, "$SpamReplaceText", $email);
$name = preg_replace($find, "$SpamReplaceText", $name);
$message = preg_replace($find, "$SpamReplaceText", $message);

// Check to see if the fields contain any content we want to ban
if(stristr($name, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
if(stristr($message, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}

// Do a check on the send email and subject text
if(stristr($sendto, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
if(stristr($subject, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();}
}
// Build the email body text
$emailcontent = "
-----------------------------------------------------------------------------
WEBSITE CONTACT ENQUIRY
-----------------------------------------------------------------------------

Name: $name
Email: $email
Message: $message

_______________________________________
End of Email
";
// Check the email address enmtered matches the standard email address format
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,6}$", $email)) {
echo "<p>It appears you entered an invalid email address</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
}

elseif (!trim($name)) {
echo "<p>Please go back and enter a Name</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
}

elseif (!trim($message)) {
echo "<p>Please go back and type a Message</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
}

elseif (!trim($email)) {
echo "<p>Please go back and enter an Email</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>";
}

// Sends out the email or will output the error message
elseif (mail($sendto, $subject, $emailcontent, $headers)) {
echo "<br><br><p><b>Thank You $name</b></p><p>We will be in touch as soon as possible.</p>";

}
}
else {
?>
<p align="center">Please complete all details of your enquiry<br>and we will get back to you shortly.</p>
<br>
<form method="post"><INPUT NAME="op" TYPE="hidden" VALUE="send">
<table width="626">
<tr>
<td><p>Name:</p></td>
<td>
<input name="name" type="text" size="40" maxlength="150">
</td>
</tr>
<tr>
<td><p>E-mail:</p></td>
<td>
<input name="email" type="text" size="40" maxlength="150">
</td>
</tr>

<tr>
<td valign="top"><p>Message:</p></td>
<td><textarea name="message" cols="80" rows="6"></textarea></td>
</tr>
<tr><td></td> <td><input name="submit" type="submit" value="Send Message"></td></tr>
</table>
</form>
<?php } ?>

<p align="center">&nbsp;</p></td>
</tr>
</table>

Re: HELP! Parse error: syntax error, unexpected T_STRING in....

Posted: Sun Jan 31, 2010 1:22 pm
by requinix

Code: Select all

$SpamErrorMessage = "<p align="center"><font color="red">Malicious code content detected.</font><br><b> Your IP Number of </b>".getenv("REMOTE_ADDR")."<b> has been logged.</b></p>";
If a string starts and ends with "s, and you put "s inside it, how is PHP to know whether the string should end or whether you want a literal quote?

Strings
Read the table.

Re: HELP! Parse error: syntax error, unexpected T_STRING in....

Posted: Sun Jan 31, 2010 1:23 pm
by AbraCadaver
Give this a read and then look closely at the line you have highlighted: http://www.php.net/manual/en/language.types.string.php

Re: HELP! Parse error: syntax error, unexpected T_STRING in....

Posted: Sun Jan 31, 2010 1:33 pm
by dek
Hi guys,

thanks for the responses, but can i just point out that i no nothing about PHP, which is why i downloaded the "Free Code" from some guys website to put into my website. I figured it would work without me having to do a course in PHP.
As there is something wrong with this line 15 and you both seem to know what it is could you just point out what the problem is so i can fix it as quickly as possible and move on.
I will study the ins and out of PHP coding when i have the time. Right now i just need the answer.

Please help.

Re: HELP! Parse error: syntax error, unexpected T_STRING in....

Posted: Sun Jan 31, 2010 1:40 pm
by infolock
Try this:

Code: Select all

 
<table width="760" border="0" cellspacing="10" cellpadding="0" align="center">
<tr>
<td align="center">
 
<?php 
if (isset($_POST["op"]) && ($_POST["op"]=="send")) { 
 
  /******** START OF CONFIG SECTION *******/
  $sendto = "nickedwards@tailoredpersonaltraining.co.uk";
  $subject = "Website Contact Enquiry";
  // Select if you want to check form for standard spam text
  $SpamCheck = "Y"; // Y or N
  $SpamReplaceText = "*content removed*";
  // Error message printed if spam form attack found
  $SpamErrorMessage = "<p align=\"center\"><font color=\"red\">Malicious code content detected.</font><br><b> Your IP Number of </b>".getenv("REMOTE_ADDR")."<b> has been logged.</b></p>";
  /******** END OF CONFIG SECTION *******/
  
  $name = $HTTP_POST_VARS['name']; 
  $email = $HTTP_POST_VARS['email']; 
  $message = $HTTP_POST_VARS['message']; 
  $headers = "From: $emailn";
  $headers . "MIME-Version: 1.0n"
  . "Content-Transfer-Encoding: 7bitn"
  . "Content-type: text/html; charset = "iso-8859-1";nn";
  if ($SpamCheck == "Y") { 
  // Check for Website URL's in the form input boxes as if we block website URLs from the form,
  // then this will stop the spammers wastignt ime sending emails
  if (preg_match("/http/i", "$name")) {echo "$SpamErrorMessage"; exit();} 
  if (preg_match("/http/i", "$email")) {echo "$SpamErrorMessage"; exit();} 
  if (preg_match("/http/i", "$message")) {echo "$SpamErrorMessage"; exit();} 
  
  // Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer 
  $pattern = '/(;|||`|>|<|&|^|"|'."n|r|'".'|{|}|[|]|)|()/i'; // build the pattern match string 
  
  $name = preg_replace($pattern, "", $name); 
  $email = preg_replace($pattern, "", $email); 
  $message = preg_replace($pattern, "", $message); 
  
  // Check for the injected headers from the spammer attempt 
  // This will replace the injection attempt text with the string you have set in the above config section
  $find = array("/bcc:/i","/Content-Type:/i","/cc:/i","/to:/i"); 
  $email = preg_replace($find, "$SpamReplaceText", $email); 
  $name = preg_replace($find, "$SpamReplaceText", $name); 
  $message = preg_replace($find, "$SpamReplaceText", $message); 
  
  // Check to see if the fields contain any content we want to ban
  if(stristr($name, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
  if(stristr($message, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
  
  // Do a check on the send email and subject text
  if(stristr($sendto, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
  if(stristr($subject, $SpamReplaceText) !== FALSE) {echo "$SpamErrorMessage"; exit();} 
  }
  // Build the email body text
  $emailcontent = <<<EOD
  ----------------------------------------------------------------------------- 
  WEBSITE CONTACT ENQUIRY
  ----------------------------------------------------------------------------- 
  
  Name: $name 
  Email: $email 
  Message: $message 
  
  _______________________________________ 
  End of Email 
EOD;
 
  // Check the email address enmtered matches the standard email address format
  if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,6}$", $email)) { 
    echo "<p>It appears you entered an invalid email address</p><p><a href='javascript&#058; history.go(-1)'>Click here to go back</a>.</p>"; 
  } elseif (!trim($name)) { 
    echo "<p>Please go back and enter a Name</p><p><a href='javascript&#058; history.go(-1)'>Click here to go back</a>.</p>"; 
  } elseif (!trim($message)) { 
    echo "<p>Please go back and type a Message</p><p><a href='javascript&#058; history.go(-1)'>Click here to go back</a>.</p>"; 
  } elseif (!trim($email)) { 
    echo "<p>Please go back and enter an Email</p><p><a href='javascript&#058; history.go(-1)'>Click here to go back</a>.</p>"; 
  } elseif (mail($sendto, $subject, $emailcontent, $headers)) { // Sends out the email or will output the error message 
    echo "<br><br><p><b>Thank You $name</b></p><p>We will be in touch as soon as possible.</p>"; 
  } 
} else { 
  echo <<<EOD
  <p align="center">Please complete all details of your enquiry<br>and we will get back to you shortly.</p>
  <br>
  <form method="post"><INPUT NAME="op" TYPE="hidden" VALUE="send"> 
  <table width="626"> 
  <tr> 
  <td><p>Name:</p></td> 
  <td> 
  <input name="name" type="text" size="40" maxlength="150"> 
  </td> 
  </tr> 
  <tr> 
  <td><p>E-mail:</p></td> 
  <td> 
  <input name="email" type="text" size="40" maxlength="150"> 
  </td> 
  </tr> 
  
  <tr> 
  <td valign="top"><p>Message:</p></td> 
  <td><textarea name="message" cols="80" rows="6"></textarea></td> 
  </tr> 
  <tr><td></td> <td><input name="submit" type="submit" value="Send Message"></td></tr> 
  </table> 
  </form>
EOD;
}
?>
 
<p align="center">&nbsp;</p></td>
</tr>
</table>
 
View the links posted above. Also view this link: http://forums.devnetwork.net/viewtopic.php?f=1&t=112183

Notice that when you start a string with double-quotes, and you use double-quotes inside of them, you must escape them using a backslash (ie: echo "hello \"jon\", here we go";)

PHP terms used:
String
Heredoc

Re: HELP! Parse error: syntax error, unexpected T_STRING in....

Posted: Sun Jan 31, 2010 1:59 pm
by dek
Thankyou so much. Problem solved. You were a great help.

Re: HELP! Parse error: syntax error, unexpected T_STRING in....

Posted: Sun Jan 31, 2010 2:55 pm
by requinix
dek wrote:thanks for the responses, but can i just point out that i no nothing about PHP, which is why i downloaded the "Free Code" from some guys website to put into my website. I figured it would work without me having to do a course in PHP.
Let's try applying that argument to other things:
- I figure I could drive a car without me having to take a driver's ed class
- I figure I could get a tax refund without having to fill out tax forms
- I figure I could defend my innocence in court without having to become a lawyer
dek wrote:As there is something wrong with this line 15 and you both seem to know what it is could you just point out what the problem is so i can fix it as quickly as possible and move on.
And then what happens next time you have a problem? You'll solve it yourself? No. You'll keep coming back which - you have to admit - takes longer to fix your problem than if you knew how to do it yourself.
dek wrote:I will study the ins and out of PHP coding when i have the time. Right now i just need the answer.
No, you won't. You might want to but you won't get around to it. And why bother when there are people on the Internet willing you give you the answer without batting an eyelash?


If anyone wants to criticize me for this response, don't bother since I won't be around to read it - seems I need to take a break from trying to help people.