phpnewbieca Posted August 3, 2013 Share Posted August 3, 2013 (edited) Has anyone heard of this error and know how to fix it: PHP Parse error: syntax error, unexpected $end on line 268 Line 268: ?> <?php // Process repair_upgradeform.html error_reporting(-1); // Create Random Number srand((double) microtime() * 1000000); //Define Variable(s) $random_number = rand(); $confirmation_number = "$random_number"; $date = date("D d M Y - H:i:s "); $order_date = date("D d M Y"); $SendTo = "coon-a@gmx.com"; $From = "coon-a@gmx.com"; $error_message = ""; //Get Data From Form $Eighteen = $_POST['Eighteen']; $List = $_POST['List']; $Dsn = $_POST['Dsn']; $Title = $_POST['Title']; $Fname = $_POST['Fname']; $Lname = $_POST['Lname']; $Suffix = $_POST['Suffix']; $Address = $_POST['Address']; $CityState = $_POST['CityState']; $Zip = $_POST['Zip']; $Email = $_POST['Email']; $Phone = $_POST['Phone']; $Phone_2 = $_POST['Phone_2']; $TypeComputer = $_POST['TypeComputer']; $ComputerBrand = $_POST['ComputerBrand']; $ComputerModel = $_POST['ComputerModel']; if(isset($_POST['Cd'])) { $Cd = $_POST['Cd']; } if(isset($_POST['Cd_rw'])) { $Cd_rw = $_POST['Cd_rw']; } if(isset($_POST['Dvd'])) { $Dvd = $_POST['Dvd']; } if(isset($_POST['Dvd_rw'])) { $Dvd_rw = $_POST['Dvd_rw']; } if(isset($_POST['GraphicCard'])) { $GraphicCard = $_POST['GraphicCard']; } if(isset($_POST['Memory'])) { $Memory = $_POST['Memory']; } if(isset($_POST['Modem'])) { $Modem = $_POST['Modem']; } if(isset($_POST['Multimedia'])) { $Multimedia = $_POST['Multimedia']; } if(isset($_POST['NetworkCard'])) { $NetworkCard = $_POST['NetworkCard']; } if(isset($_POST['Software'])) { $SoundCard = $_POST['Software']; } if(isset($_POST['SoundCard'])) { $SoundCard = $_POST['SoundCard']; } if(isset($_POST['Speakers'])) { $Speakers = $_POST['Speakers']; } $Comments = $_POST['Comments']; $FnameUc = ucfirst($Fname); $LnameUc = ucfirst($Lname); $order_num = "$order_date-$LnameUc-$confirmation_number"; // validate expected data exists and is in the correct format ($Fname, $Lname, and $Email) if(!isset($_POST['Eighteen'])) { echo "No Age Verification.\n"; die(); } if(!isset($_POST['List'])) { echo "No Type Service.\n"; die(); } if(!isset($_POST['Dsn'])) { echo "No Date Service Needed.\n"; die(); } if(!isset($_POST['Fname'])) { echo "No First Name.\n"; died(); } if(!isset($_POST['Lname'])) { echo "No Last Name.\n"; died(); } if(!isset($_POST['CityState'])) { echo "No City\State.\n"; die(); } if(!isset($_POST['Email'])) { echo "No Email address.\n"; die(); } if (check_email_address($Email)) { //echo $Email . " "; } else { echo $Email . " is not a valid email address.\n"; die(); } // Call Functions Repair_Upgrade_3(); //FUNCTIONS function died() { global $date, $SendTo, $From, $error_message, $confirmation_number, $order_num, $Eighteen, $List, $Dsn, $Title, $Fname, $Lname, $Suffix, $Address, $CityState, $Zip, $Email, $Phone, $Phone_2, $TypeComputer, $ComputerBrand, $ComputerModel, $Cd, $Cd_rw, $Dvd, $Dvd_rw, $GraphicCard, $Memory, $Modem, $Multimedia, $NetworkCard, $Software, $SoundCard, $Speakers, $Comments; // 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 = ""; $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$Fname)) { $error_message.= 'The First Name you entered does not appear to be valid.<br />'; die(); } if(!preg_match($string_exp,$Lname)) { $error_message.= 'The Last Name you entered does not appear to be valid.<br />'; die(); } $string_exp = "/^[A-Za-z0-9 !-.,:;?']+$/"; if(!preg_match($string_exp,$Comments)) { $error_message.= 'You used invalid charaters in the comments box.<br />'; } if(strlen($Comments) < 2) { $error_message.= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { die($error_message); } function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } function check_email_address($Email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $Email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. echo "Email invalid because wrong number of characters in one section, or wrong number of @ symbols.\n"; echo "<br />\n"; return false; } // Split it into sections to make life easier $Email_array = explode("@", $Email); $local_array = explode(".", $Email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",$local_array[$i])) { echo "Split it into sections to make life easier\n"; echo "<br />\n"; return false; } } if (!ereg("^\[?[0-9\.]+\]?$",$Email_array[1])) { // Check if domain is IP. If not, it should be valid domain name //echo "Check if domain is IP. If not, it should be valid domain name\n"; //echo "<br />\n"; $domain_array = explode(".", $Email_array[1]); if(sizeof($domain_array) < 2) { return false; // Not enough parts to domain echo "Not enough parts to domain\n"; echo "<br />\n"; } for ($i = 0; $i < sizeof($domain_array); $i++) { if(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } function Repair_Upgrade_3() { // Email Customer HTML global $date, $SendTo, $From, $error_message, $confirmation_number, $order_num, $Eighteen, $List, $Dsn, $Title, $Fname, $Lname, $Suffix, $Address, $CityState, $Zip, $Email, $Phone, $Phone_2, $TypeComputer, $ComputerBrand, $ComputerModel, $Cd, $Cd_rw, $Dvd, $Dvd_rw, $GraphicCard, $Memory, $Modem, $Multimedia, $NetworkCard, $Software, $SoundCard, $Speakers, $Comments; // Upper case First and last names $FnameUc = ucfirst($Fname); $LnameUc = ucfirst($Lname); //Create Array $List2=array(); if($Cd) { $List2[0]="CD<br>"; } if($Cd_rw) { $List2[1]="CD RW"<br>; } if($Dvd) { $List2[2]="DVD<br>"; } if($Dvd_rw) { $List2[3]="DVD RW<br>"; } if($GraphicCard) { $List2[4]="Graphic Card<br>"; } if($Memory) { $List2[5]="Memory<br>"; } if($Modem) { $List2[6]="Modem<br>"; } if($Multimedia) { $List2[7]="Multimedia<br>"; } if($NetworkCard) { $List2[8]="Network Card<br>"; } if($Software) { $List2[9]="Software<br>"; } if$SoundCard) { $List2[10]="Sound Card<br>"; } if($Speakers) { $List2[11]="Speakers<br><br>"; } $subject = "RE: Repair/Upgrade Order -- HTML\n\n"; //begin of HTML message $message = <<<EOF <html> <body BGCOLOR='tan' TEXT='black'><br> Hello $FnameUc<br> We received your request for Service: $date.<br><br> The Order you submitted is below.<br> You are 18 years or older? $Eighteen<br> Type Service: $List<br> Date service needed: $Dsn<br> $Title $FnameUc $LnameUc $Suffix<br> $Address<br> $CityState $Zip<br> $Email<br> Daytime Phone: $Phone<br> Evening Phone: $Phone_2<br> <b>Computer Information</b><br> Type Computer: $TypeComputer<br> Computer Brand: $ComputerBrand<br> Computer Model: $ComputerModel<br><br> <b>Items to $List</b><br> $List2[0] $List2[1] $List2[2] $List2[3] $List2[4] $List2[5] $List2[6] $List2[7] $List2[8] $List2[9] $List2[10] $List2[11] <b>Comments</b><br> $Comments<br><br> "CONFIRMATION NUMBER: $confirmation_number<br> ORDER NUMBER: $order_num<br> You will need your CONFIRMATION NUMBER to validate your ORDER.<br> <br> </body> </html> EOF; //end of message $headers = "From: $From\r\n"; $headers .= "Content-type: text/html\r\n"; //$headers .= "Cc: [email]coon-a@gmx.com[/email]"; //options to send to cc+bcc //$headers .= "Cc: [email]email@maaking.cXom[/email]"; //$headers .= "Bcc: [email]email@maaking.cXom[/email]"; // now lets send the email. mail($Email, $subject, $message, $headers); echo " "; } ?> Edited August 3, 2013 by phpnewbieca Quote Link to comment https://forums.phpfreaks.com/topic/280804-php-parse-error-syntax-error-unexpected-end/ Share on other sites More sharing options...
jcbones Posted August 3, 2013 Share Posted August 3, 2013 Unexpected ends are almost always missing closing braces }. In your case, it is because your heredoc syntax is wrong, in that the closing line must be on it's own line WITH NO WHITESPACE BEFORE it. Which means that the script is seeing everything past $message= <<<EOF as a string. Geany editor caught it in about 2 seconds. Quote Link to comment https://forums.phpfreaks.com/topic/280804-php-parse-error-syntax-error-unexpected-end/#findComment-1443367 Share on other sites More sharing options...
phpnewbieca Posted August 4, 2013 Author Share Posted August 4, 2013 (edited) I agree "Unexpected ends are almost always missing closing braces }." I learned that after reading this article: http://en.kioskea.net/faq/3377-parse-error-syntax-error-unexpected-end I not quite sure I understand what you have written: Why? The closing line is Line now 271: ?> because I added a few lines of code but there is no white space before it or after it If you are referring to this line: $message= <<<EOF there is no white space before it or after it. I downloaded and installed Geany editor today. Please Please tell me how to detect code errors with it or where I can read how to detect missing brackets, white space, etc. with it. <?php // Process repair_upgradeform.html error_reporting(-1); // Create random number srand ((double) microtime() * 1000000); //Define Variable(s) $random_number = rand(); $confirmation_number = "$random_number"; $date = date("D d M Y - H:i:s "); $order_date = date("D d M Y"); $SendTo = "coon-a@gmx.com"; $From = "coon-a@gmx.com"; $error_message = ""; //Get Data From Form $Eighteen = $_POST['Eighteen']; $List = $_POST['List']; $Dsn = $_POST['Dsn']; $Title = $_POST['Title']; $Fname = $_POST['Fname']; $Lname = $_POST['Lname']; $Suffix = $_POST['Suffix']; $Address = $_POST['Address']; $CityState = $_POST['CityState']; $Zip = $_POST['Zip']; $Email = $_POST['Email']; $Phone = $_POST['Phone']; $Phone_2 = $_POST['Phone_2']; $TypeComputer = $_POST['TypeComputer']; $ComputerBrand = $_POST['ComputerBrand']; $ComputerModel = $_POST['ComputerModel']; if(isset($_POST['Cd'])) { $Cd = $_POST['Cd']; } if(isset($_POST['Cd_rw'])) { $Cd_rw = $_POST['Cd_rw']; } if(isset($_POST['Dvd'])) { $Dvd = $_POST['Dvd']; } if(isset($_POST['Dvd_rw'])) { $Dvd_rw = $_POST['Dvd_rw']; } if(isset($_POST['GraphicCard'])) { $GraphicCard = $_POST['GraphicCard']; } if(isset($_POST['Memory'])) { $Memory = $_POST['Memory']; } if(isset($_POST['Modem'])) { $Modem = $_POST['Modem']; } if(isset($_POST['Multimedia'])) { $Multimedia = $_POST['Multimedia']; } if(isset($_POST['NetworkCard'])) { $NetworkCard = $_POST['NetworkCard']; } if(isset($_POST['Software'])) { $SoundCard = $_POST['Software']; } if(isset($_POST['SoundCard'])) { $SoundCard = $_POST['SoundCard']; } if(isset($_POST['Speakers'])) { $Speakers = $_POST['Speakers']; } $Comments = $_POST['Comments']; //Define Variable $order_num = "$order_date-$LnameUc-$confirmation_number"; // validate expected data exists and is in the correct format ($Fname, $Lname, and $Email) if(!isset($_POST['Eighteen'])) { echo "No Age Verification.\n"; die(); } if(!isset($_POST['List'])) { echo "No Type Service.\n"; die(); } if(!isset($_POST['Dsn'])) { echo "No Date Service Needed.\n"; die(); } if(!isset($_POST['Fname'])) { echo "No First Name.\n"; died(); } if(!isset($_POST['Lname'])) { echo "No Last Name.\n"; died(); } if(!isset($_POST['CityState'])) { echo "No City\State.\n"; die(); } if(!isset($_POST['Email'])) { echo "No Email address.\n"; die(); } if (check_email_address($Email)) { echo $Email . " "; } else { echo $Email . " is not a valid email address.\n"; die(); } // Call Functions Repair_Upgrade_3(); //FUNCTIONS function died() { global $error_message; // 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(); } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$Fname)) { $error_message.= 'The First Name you entered does not appear to be valid.<br />'; die(); } if(!preg_match($string_exp,$Lname)) { $error_message.= 'The Last Name you entered does not appear to be valid.<br />'; die(); } if(strlen($error_message) > 0) { die($error_message); } function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } function check_email_address($Email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $Email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. echo "Email invalid because wrong number of characters in one section, or wrong number of @ symbols.\n"; echo "<br />\n"; return false; } // Split it into sections to make life easier $Email_array = explode("@", $Email); $local_array = explode(".", $Email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",$local_array[$i])) { echo "Split it into sections to make life easier\n"; echo "<br />\n"; return false; } } if (!ereg("^\[?[0-9\.]+\]?$",$Email_array[1])) { // Check if domain is IP. If not, it should be valid domain name //echo "Check if domain is IP. If not, it should be valid domain name\n"; //echo "<br />\n"; $domain_array = explode(".", $Email_array[1]); if(sizeof($domain_array) < 2) { return false; // Not enough parts to domain echo "Not enough parts to domain\n"; echo "<br />\n"; } for ($i = 0; $i < sizeof($domain_array); $i++) { if(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } function Repair_Upgrade_3() { // Email Customer HTML global $date, $SendTo, $From, $error_message, $confirmation_number, $order_num, $Eighteen, $List, $Dsn, $Title, $Fname, $Lname, $Suffix, $Address, $CityState, $Zip, $Email, $Phone, $Phone_2, $TypeComputer, $ComputerBrand, $ComputerModel, $Cd, $Cd_rw, $Dvd, $Dvd_rw, $GraphicCard, $Memory, $Modem, $Multimedia, $NetworkCard, $Software, $SoundCard, $Speakers, $Comments; // Upper case First and last names $FnameUc = ucfirst($Fname); $LnameUc = ucfirst($Lname); //Create Array $List2=array(); if($Cd) { $List2[0]="CD<br>"; } if($Cd_rw) { $List2[1]="CD RW<br>"; } if($Dvd) { $List2[2]="DVD<br>"; } if($Dvd_rw) { $List2[3]="DVD RW<br>"; } if($GraphicCard) { $List2[4]="Graphic Card<br>"; } if($Memory) { $List2[5]="Memory<br>"; } if($Modem) { $List2[6]="Modem<br>"; } if($Multimedia) { $List2[7]="Multimedia<br>"; } if($NetworkCard) { $List2[8]="Network Card<br>"; } if($Software) { $List2[9]="Software<br>"; } if($SoundCard) { $List2[10]="Sound Card<br>"; } if($Speakers) { $List2[11]="Speakers<br><br>"; } $subject = "RE: Repair/Upgrade Order -- HTML\n\n"; //begin of HTML message $message = <<<EOF <html> <body BGCOLOR='tan' TEXT='black'><br> Hello $FnameUc<br> We received your request for Service: $date.<br><br> The Order you submitted is below.<br> Are you 18 years or older? $Eighteen<br> Type Service: $List<br> Date service needed: $Dsn<br> $Title $FnameUc $LnameUc $Suffix<br> $Address<br> $CityState $Zip<br> $Email<br> Daytime Phone: $Phone<br> Evening Phone: $Phone_2<br> <b>Computer Information</b><br> Type Computer: $TypeComputer<br> Computer Brand: $ComputerBrand<br> Computer Model: $ComputerModel<br><br> <b>Items to $List</b><br> $List2[0] $List2[1] $List2[2] $List2[3] $List2[4] $List2[5] $List2[6] $List2[7] $List2[8] $List2[9] $List2[10] $List2[11] <b>Comments</b><br> $Comments<br><br> CONFIRMATION NUMBER: $confirmation_number<br> ORDER NUMBER: $order_num<br> You will need your CONFIRMATION NUMBER to validate your ORDER.<br> <br> </body> </html> EOF; //end of message $headers = "From: $From\r\n"; $headers.= "Content-type: text/html\r\n"; //$headers.= "Cc: [email]horacef@horacefranklinjr.com[/email]"; //options to send to cc+bcc //$headers.= "Cc: [email]email@maaking.cXom[/email]"; //$headers.= "Bcc: [email]email@maaking.cXom[/email]"; // now lets send the email. mail($Email, $subject, $message, $headers); echo " "; } ?> Edited August 4, 2013 by phpnewbieca Quote Link to comment https://forums.phpfreaks.com/topic/280804-php-parse-error-syntax-error-unexpected-end/#findComment-1443419 Share on other sites More sharing options...
mac_gyver Posted August 4, 2013 Share Posted August 4, 2013 the closing EOF; tag is where the offending white-space is at. the following is from the php.net documentation for the heredoc syntax you are trying to use in your code - WarningIt is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline. If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one. If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line. Heredocs can not be used for initializing class properties. Since PHP 5.3, this limitation is valid only for heredocs containing variables. Example #1 Invalid example <?phpclass foo { public $bar = <<<EOTbar EOT;}?> Quote Link to comment https://forums.phpfreaks.com/topic/280804-php-parse-error-syntax-error-unexpected-end/#findComment-1443423 Share on other sites More sharing options...
Solution phpnewbieca Posted August 5, 2013 Author Solution Share Posted August 5, 2013 (edited) First, I would like to apologize to jcbones. The reason I could not understand your answer is I could not see the white space with Notepad++. After I downloaded, installed Geany editor and checked "Show white space" I understood your answer. Second, I would like to Thank mac_gyver for his response. Problem solved Edited August 5, 2013 by phpnewbieca Quote Link to comment https://forums.phpfreaks.com/topic/280804-php-parse-error-syntax-error-unexpected-end/#findComment-1443573 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.