Jump to content

Parse Error help please.


Ozmo

Recommended Posts

Hello,

 

I do not know PHP, but am trying to use some code to send text input from a form to an email address. However, I keep getting a parse error when I test my page. I have looked through several previous posts on these boards about similar problems, and have still not been able to figure this out. Any help would be greatly appreciated!

 

The error is this:

 

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/littlera/public_html/test/contact_process.php on line 2

 

Parse error: syntax error, unexpected T_STRING in /home/littlera/public_html/test/contact_process.php on line 2

 

...and here is the code:

 

<?php

/* PHP Form Mailer - phpFormMailer v2.2, last updated 23rd Jan 2008 - check back often for updates!

  (easy to use and more secure than many cgi form mailers) FREE from:

                  www.TheDemoSite.co.uk

      Should work fine on most Unix/Linux platforms

      for a Windows version see: asp.thedemosite.co.uk

*/

 

// ------- three variables you MUST change below  -------------------------------------------------------

$replyemail="littlera@littlerangoon.com";//change to your email address

$valid_ref1="http://littlerangoon.com/contact.html";// chamge "Your--domain" to your domain

$valid_ref2="http://www.littlerangoon.com/contact.html";// chamge "Your--domain" to your domain

// -------- No changes required below here -------------------------------------------------------------

// email variable not set - load $valid_ref1 page

if (!isset($_POST['email']))

{

echo "<script language=\"JavaScript\"><!--\n ";

echo "top.location.href = \"$valid_ref1\"; \n// --></script>";

exit;

}

 

$ref_page=$_SERVER["HTTP_REFERER"];

$valid_referrer=0;

if($ref_page==$valid_ref1) $valid_referrer=1;

elseif($ref_page==$valid_ref2) $valid_referrer=1;

if(!$valid_referrer)

{

echo "<script language=\"JavaScript\"><!--\n alert(\"ERROR - not sent.\\n\\nCheck your 'valid_ref1' and 'valid_ref2' are correct within contact_process.php.\");\n";

echo "top.location.href = \"contact.html\"; \n// --></script>";

exit;

}

 

//check user input for possible header injection attempts!

function is_forbidden($str,$check_all_patterns = true)

{

$patterns[0] = 'content-type:';

$patterns[1] = 'mime-version';

$patterns[2] = 'multipart/mixed';

$patterns[3] = 'Content-Transfer-Encoding';

$patterns[4] = 'to:';

$patterns[5] = 'cc:';

$patterns[6] = 'bcc:';

$forbidden = 0;

for ($i=0; $i<count($patterns); $i++)

  {

  $forbidden = eregi($patterns[$i], strtolower($str));

  if ($forbidden) break;

  }

//check for line breaks if checking all patterns

if ($check_all_patterns AND !$forbidden) $forbidden = preg_match("/(%0a|%0d|\\n+|\\r+)/i", $str);

if ($forbidden)

{

  echo "<font color=red><center><h3>STOP! Message not sent.</font></h3><br><b>

        The text you entered is forbidden, it includes one or more of the following:

        <br><textarea rows=9 cols=25>";

  foreach ($patterns as $key => $value) echo $value."\n";

  echo "\\n\n\\r</textarea><br>Click back on your browser, remove the above characters and try again.

        </b><br><br><br><br>Thankfully protected by phpFormMailer freely available from:

        <a href=\"http://thedemosite.co.uk/phpformmailer/\">http://thedemosite.co.uk/phpformmailer/</a>";

  exit();

}

else return $str;

}

 

$name = is_forbidden($_POST["name"]);

$email = is_forbidden($_POST["email"]);

$thesubject = is_forbidden($_POST["thesubject"]);

$themessage = is_forbidden($_POST["themessage"], false);

 

$success_sent_msg='<p align="center"><strong> </strong></p>

                  <p align="center"><strong>Your message has been successfully sent to us<br>

                  </strong> and we will reply as soon as possible.</p>

                  <p align="center">A copy of your query has been sent to you.</p>

                  <p align="center">Thank you for contacting us.</p>';

 

$replymessage = "Hi $name

 

Thank you for your email.

 

We will endeavour to reply to you shortly.

 

Please DO NOT reply to this email.

 

Below is a copy of the message you submitted:

--------------------------------------------------

Subject: $thesubject

Query:

$themessage

--------------------------------------------------

 

Thank you";

 

$themessage = "name: $name \nQuery: $themessage";

mail("$replyemail",

    "$thesubject",

    "$themessage",

    "From: $email\nReply-To: $email");

mail("$email",

    "Receipt: $thesubject",

    "$replymessage",

    "From: $replyemail\nReply-To: $replyemail");

echo $success_sent_msg;

/*

  PHP Form Mailer - phpFormMailer (easy to use and more secure than many cgi form mailers)

  FREE from:

 

    www.TheDemoSite.co.uk      */

?>

Link to comment
Share on other sites

I'm sorry, I don't understand.  :(

 

Narrow it down how? Not include the entire code in my post? What if I omitted the problem area inadvertently?

 

I have gone over this code over and over and cannot figure how I am getting an error about line 2 and an unexpected '\'.  I don't see anything that looks wrong anywhere near line 2.

 

But, like I said, I have never used PHP before.

 

Does anybody see what is wrong with this code?

Link to comment
Share on other sites

The syntax of the code you posted is correct for PHP. However, I would remove the two forward slashes on this line:

 

echo "top.location.href = \"$valid_ref1\"; \n// --></script>";

 

so that you're not commenting out the end of the script tag. So, it should be:

 

echo "top.location.href = \"$valid_ref1\"; \n --></script>";

 

Make sure you post the code content of contact_process.php which is where the error is.

 

 

FYI: The PHP help area is for people who are learning and writing their own PHP code. If you didn't write the code, then it should be posted in the third-party scripts topic area. thanks.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.