Jump to content

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING


mark103

Recommended Posts

Hello guys,

 

I have a problem with the php, I have got an parse error, the error is: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/myuser/public_html/mysite.com/email.php on line 69

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'user');
    define('DB_PASSWORD', 'pass');
    define('DB_DATABASE', 'mydbname');
       
$errmsg_arr = array();
    $errflag = false;

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {

die('Failed to connect to server: ' . mysql_error());
    }

    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {

die("Unable to select database");
    }

   function clean($var){

return mysql_real_escape_string(strip_tags($var));
    }
    $name = clean($_GET['name']);
    $email = clean($_GET['email']);
    $comments = clean($_GET['comments']);
    $rate = clean($_GET['rate']);
    if($name == '') {
  $errmsg_arr[] = 'name or member ID missing';
  $errflag = true;
    }
   else {
    }

    if($errflag) {
  $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  echo implode('<br />',$errmsg_arr);
   }
   else {
$insert = array();
if(isset($_GET['name'])) {
    $insert[] = 'member_or_from = \'' . clean($_GET['name']) .'\'';
   // echo "tested";    
}
if(isset($_GET['email'])) {
    $insert[] = 'email_address = \'' . clean($_GET['email']) . '\'';
}
if(isset($_GET['comments'])) {
    $insert[] = 'comments = \'' . clean($_GET['comments']) . '\'';
}
if(isset($_GET['rate'])) {
    $insert[] = 'rate = \'' . clean($_GET['rate']) . '\'';
}
if (count($insert)>0) {
   $names = implode(',',$insert);

if(isset($name)) {
   $to = "[email protected]";
   $subject = $type';
   $message = '$comments', '$rate';
   $headers = 'From: $name '@myemail.com''
   mail($to, $subject, $message, $headers);
   }
   else {
   $to = "[email protected]";
   $subject = $type';
   $message = '$comments', '$rate';
   $headers = 'From: $email'
   mail($to, $subject, $message, $headers);

if (!mysql_query($sql,$link))
  {
  die('Error: ' . mysql_error());
  }
echo "Thank you for sent us the feedback";
  }
}
}
?>

 

 

I don't know where it went wrong in line 69.

 

Please could any of you help me to correct the problem I am getting??

 

Any advise would be much appreciate.

In this chunk of code, you have 3 syntax errors, which I have indicated with comments in your script:

<?php
	if(isset($name)) {
		$to = "[email protected]";
		$subject = $type';    // <------ extra single quote -- remove it
		$message = '$comments', '$rate';
		$headers = 'From: $name '@myemail.com''
		mail($to, $subject, $message, $headers);
		}
		else {
		$to = "[email protected]";
		$subject = $type';   // <------ extra single quote -- remove it
		$message = '$comments', '$rate';
		$headers = 'From: $email'   // <----------- no terminating semi-colon
		mail($to, $subject, $message, $headers);

		if (!mysql_query($sql,$link))
		{
			die('Error: ' . mysql_error());
		}
		echo "Thank you for sent us the feedback";
	}
?>

 

Ken

Thanks ken, I have fixed all of the problems which I have removed the extra single quote in some lines.

 

However, could you please help me with this:

 

if(isset($name)) {
   $to = "[email protected]";
   $subject = $type;
   $message = $comments & $rate;
   $headers = "[email protected]";
   mail($to, $subject, $message, $headers);
echo "Thank you for sent us your feedback";
   }
   else {
if(isset($email)) {
   $to = "[email protected]";
   $subject = $type;
   $message = $comments && $rate;
   $headers = $email;
   mail($to, $subject, $message, $headers);
  }

 

 

I have problem with some of the methods included the $headers and $message. How can I get the headers to included with the email where it have came from, e.g: [email protected]. I have only get [email protected]. how can i included something are like "[email protected]"  and how can I included the $comments and $rate into the email body?

The $headers variable contains header lines for smtp email, so to get an email message to be "from" an email address, you have to include the keyword "From:"

 

So, use something like:

 

<?php
if(isset($name)) {
   $to = "[email protected]";
   $subject = $type;
   $message = $comments & $rate;
   $headers = "From: [email protected]";
   mail($to, $subject, $message, $headers);
echo "Thank you for sent us your feedback";
   }
   else {
if(isset($email)) {
   $to = "[email protected]";
   $subject = $type;
   $message = $comments && $rate;
   $headers = 'From: ' . $email;
   mail($to, $subject, $message, $headers);
  }
?>

 

BTW, what are you trying to do with these lines:

<?php
$message = $comments & $rate;
?>

<?php
$message = $comments && $rate;
?>

 

Ken

Thanks Ken, so three things that I need to make some changes on here:

 

$headers = "From: [email protected]";

 

how do I extract the value from the $name method to input them into the $headers?

 

Something is like this:

 

$headers = "From: ($_GET['name']) & ""@myemail.com"";

 

As for this line, I am trying to extract the values from $rate and $comments into $message method. How I could do that??

 

$message = $comments && $rate;

 

 

As well, how can I modify the mailed-by header?

 

I want to change the mailed-by header from 'myservername.com' to 'myownservername.com'

Why are you using the "&" for string concatenation? The "." is the concatenation operator.

 

<?php
$headers = "From: {$_GET['name']}@myemail.com";
?>

This assumes that $_GET['name'] holds the first part of an email address

 

<?php
$message = $comments . ' ' . $rate;
?>

or

<?php
$message = "$comments $rate";
?>

 

I suggest you read up on the PHP syntax and operators either in the PHP Manual or at W3schools.com

 

Ken

Thanks Ken, and the last thing I need is how can I modify the mailed-by header?

 

I get something is like: myservername.com

 

I want to change the mailed-by header from 'myservername.com' to 'myownservername.com'

 

How I can could modify for mailed-by header?

Not that one I mean, I said that how I can change the Mailed-by hostname to my own hostname? Don't you know what mailed-by header suppose to mean?

 

if you are not sure, check it here:

 

http://bbpress.org/forums/topic/php-mail...e-hostname

 

And this:

 

http://discussion.dreamhost.com/thread-100033.html

 

If you get this, then do you know how I can change the hostname to my own mailed-by hostname?

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.