phpnewbieca Posted February 12, 2010 Share Posted February 12, 2010 I received the following error: Parse error: syntax error, unexpected T_STRING in /home/xxxxxxx/public_html/sendmail.php on line 30 THIS IS LINE 30 ==> Sendmail(); I read this error means there is a missing semicolon, closing bracket, or closing quote. I checked the php file for those errors and i could not find a missing semicolon, closing bracket, or closing quote. I even checked for closing parenthesis to no avail. Maybe it is because I have been working with the file to long and need another pair of eyes.. Please check the php file below (line 30 is marked) for the error indicated by the error message above and tell me what I did wrong. <?php // processess Sendemailform.html error_reporting(E_ALL); // Define variables $Date = date("F d, Y"); // Get Data From Form // validate expected data exists if(isset($_POST['Email'])) { $Email = $_POST['Email']; } if(isset($_POST['Email_2'])) { $Email_2 = $_POST['Email_2']; } if(isset($_POST['Subject'])) { $Subject = $_POST['Subject']; } if(isset($_POST['Text'])) { $Text = $_POST['Text']; } if(isset($_POST['Attachedfile'])) { $Attachedfile = $_POST['Attachedfile']; // Call Function Fileup(); Attachedfile(); LINE 30 ==> Sendmail(); } else { // Call Function Sendmail(); } // Upload File function Fileup() { global $Date, $Yr, $Attachedfile; $target_path = "/home/xxxxxxxxx/public_html/upload"; $target_path = $target_path . basename($_FILES['Attachedfile']['name']) ; $ok=1; //This is our size condition if ($Attachedfile > 2097152) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($Attachedfile == "text/php") { echo "No PHP files<br>"; $ok=0; } //if ($Attachedfile == "application/octet-stream") { // echo "No EXE files<br>"; // $ok=0; //} //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['Attachedfile']['tmp_name'], $target_path)) { echo "Success!"; } else { echo "Sorry, there was a problem uploading your file."; } } } // FUNCTION function Attachedfile() { global $Date, $Yr, $Attachedfile; // Print to Browser echo "<html>\n"; echo "<head>\n"; echo "<title>Attached File</title>\n"; echo "</head>\n"; echo "<body BGCOLOR='Tan' TEXT='Black'>\n"; echo "<table width='600' Align='center'>\n"; echo "<tr>\n"; echo "<td width='600' Align='center'>\n"; echo "<font size='+2'>~ ~ ~ ATTACHED FILE ~ ~ ~</font>\n"; echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; echo "<table width='600' Align='center'>\n"; echo " <tr>\n"; echo "<td width='600' Align='left'>\n"; echo "The file you Attached to the email is :$Attachedfile\n"; echo "<br /><br />\n"; echo " Please visit us again <a href=\"http://www.horace-franklin-jr.com\">www.horace-franklin-jr.com</a>\n"; echo " </td>\n"; echo " </tr>\n"; echo " </table>\n"; echo " </body>\n"; echo " </html>"; } // FUNCTION function Sendmail() { global $Email, $Email_2, $Subject, $Text, $Attachedfile; // FUNCTION function died() { global $Email, $Email_2, $Subject, $Text, $Attachedfile; // your error code can go here echo "These errors appear below.\n"; echo "<br /><br />\n"; echo "$error_message\n"; echo "<br /><br />\n"; echo "Please go back and fix these errors.\n"; echo "<br /><br />\n"; die(); } $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$Email)) { $error_message.= 'The Email Address you entered does not appear to be valid.<br />'; } if(!eregi($email_exp,$Email_2)) { $error_message.= 'The Email Address you entered does not appear to be valid.<br />'; } if(strlen($Text) < 2) { $error_message.= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { die($error_message); } //FUNCTION function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $SendTo = '$Email'; $From = '$Email_2'; $Subject = "$Subject"; //supply the text and html versions of your email message $message = "$Text\n"; $html = "$Text\n"; //provide path to the file to be attached $file = '/home/xxxxxxx/public_html/upload/$Attachedfile'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r',time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: "."<"."$From".">"."\n"; $headers.= "Reply-To: "."<"."$From".">"; $headers.= "CC: "."<"."[email protected]".">"; //add boundary string and mime type specification $headers.= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-{$random_hash} \""; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents($file))); //define the body of the message. $body = "--PHP-mixed-{$random_hash}\r\n". "Content-Type: multipart/alternative; boundary=\"PHP-alt-{$random_hash}\"\r\n". "--PHP-alt-{$random_hash}\r\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n". "{$message}\r\n\r\n"."--PHP-alt-{$random_hash}\r\n\r\n". "Content-Type: text/html; charset=\"iso-8859-1\"\r\n". "Content-Transfer-Encoding: 7bit\r\n\r\n". "{$html}\r\n\r\n". "--PHP-alt-{$random_hash}--\r\n\r\n"."--PHP-mixed-{$random_hash}\r\n". "Content-Type: ".mime_content_type($file)."; name=\"". basename($file)."\"\r\n"."Content-Transfer-Encoding: base64\r\n". "Content-Disposition: attachment\r\n\r\n"."{$attachment}\r\n". "--PHP-mixed-{$random_hash}--\r\n\r\n"; //send the email $mail_sent = @mail($SendTo, $Subject, $body, $headers); if($mail_sent) { echo $mail_sent; echo "Email Sent\n"; } else { echo "Email was not sent\n"; } } ?> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/191841-unexpected-t_string-error/ Share on other sites More sharing options...
Catfish Posted February 12, 2010 Share Posted February 12, 2010 i tried this code on my server, with some modification, I am not getting the error you are getting so it must not have any issues with that line. I can't see any errors. Anyone else? Quote Link to comment https://forums.phpfreaks.com/topic/191841-unexpected-t_string-error/#findComment-1011195 Share on other sites More sharing options...
teamatomic Posted February 12, 2010 Share Posted February 12, 2010 Its not your code, or at least how it stands doing nothing. I put it in my editor and then adjusted the two mail vars and the text vars so they were valid and there was no errors. well, except for changing the negation of your email validation. That would tell me to look at the data from the form and what you do with it on the way to Sendmail(). This is what I got back when I echo the stuff you send to Sendmail at the end of your script. $Email --PHP-mixed-22d8982beb8a4a655a15a0925b7ff9fe Content-Type: multipart/alternative; boundary="PHP-alt-22d8982beb8a4a655a15a0925b7ff9fe" --PHP-alt-22d8982beb8a4a655a15a0925b7ff9fe Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit --PHP- alt-22d8982beb8a4a655a15a0925b7ff9fe Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit --PHP- alt-22d8982beb8a4a655a15a0925b7ff9fe-- --PHP-mixed-22d8982beb8a4a655a15a0925b7ff9fe Content-Type: text/txt; name="test.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment MTI3LjAuMC4xCjEyMy4yMzQuMjQyLjIzCjEzNC4yMzIuMjMyLjEzNAoxMjcuMC4wLjEKMTIzLjEz NC4yNDIuMjNrCmEyMzQuMjMyLjIzMi4xMzQK --PHP-mixed-22d8982beb8a4a655a15a0925b7ff9fe-- /n From: <$Email_2> Reply-To: <$Email_2>CC: Content-Type: multipart/mixed; boundary="PHP-mixed-22d8982beb8a4a655a15a0925b7ff9fe " If you notice there are vars in there. You are not putting through your email addys. When you have a problem you have to start echo or print_r on stuff to see if you are in fact getting what you think you are to wherever it should go or be. You problem stems from the mis-use of quotes in your sendto and from. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/191841-unexpected-t_string-error/#findComment-1011204 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.