mark103 Posted January 15, 2011 Share Posted January 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/ Share on other sites More sharing options...
Psycho Posted January 15, 2011 Share Posted January 15, 2011 Were you looking at the right line? The problem is pretty obvious $subject = $type'; You need to remove the single quote at the end. Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1159864 Share on other sites More sharing options...
mark103 Posted January 15, 2011 Author Share Posted January 15, 2011 You have choose the incorrect line. The line 69 is here: $message = '$comments, $rate'; I don't know where the problem is. Do you know where the problem is and what I should get rid of? Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1159867 Share on other sites More sharing options...
kenrbnsn Posted January 15, 2011 Share Posted January 15, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1159870 Share on other sites More sharing options...
mark103 Posted January 15, 2011 Author Share Posted January 15, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1159883 Share on other sites More sharing options...
kenrbnsn Posted January 15, 2011 Share Posted January 15, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1159899 Share on other sites More sharing options...
mark103 Posted January 15, 2011 Author Share Posted January 15, 2011 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' Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1159925 Share on other sites More sharing options...
mark103 Posted January 15, 2011 Author Share Posted January 15, 2011 bump! Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1159994 Share on other sites More sharing options...
kenrbnsn Posted January 16, 2011 Share Posted January 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1160003 Share on other sites More sharing options...
mark103 Posted January 16, 2011 Author Share Posted January 16, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1160015 Share on other sites More sharing options...
Pikachu2000 Posted January 16, 2011 Share Posted January 16, 2011 Check here for information on how to set headers: mail Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1160018 Share on other sites More sharing options...
mark103 Posted January 16, 2011 Author Share Posted January 16, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1160030 Share on other sites More sharing options...
Pikachu2000 Posted January 16, 2011 Share Posted January 16, 2011 The link to the manual shows you exactly how. You just have to read it. Quote Link to comment https://forums.phpfreaks.com/topic/224542-parse-error-syntax-error-unexpected-t_constant_encapsed_string/#findComment-1160038 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.