title: Trying to add a captcha and getting an unexpected $end but can't find it...advice needed
body: <p>I need some help I am trying to add a captcha to a page and I am getting a unexpected $end error on the very last line of this code and I can't figure out why or where I goofed . BTW I didn't include the private key here but it IS in my code.</p>
  
  <pre><code>&lt;?php
    require_once('recaptchalib.php');
    $privatekey = "your_private_key";
    $resp = recaptcha_check_answer ($privatekey,
                              $_SERVER["REMOTE_ADDR"],
                              $_POST["recaptcha_challenge_field"],
                              $_POST["recaptcha_response_field"]);
  
   if (!$resp-&gt;is_valid) {
  // What happens when the CAPTCHA was entered incorrectly
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp-&gt;error . ")");
   } else {
  // Your code here to handle a successful verification$problems = array();
      $showform = 0;
       $errorMessage = "";
  
      function validate($field, $value) {
  
          // || $field == "id" || $field == "phone" || $field == "course" || $field == "instructor"
  
          /*if ($field == "name" || $field == "email" || $field == "computers" || $field == "info") {*/
              if ($value == "") {
                  return 0;
              } else {
                  return 1;
              }
          /*}*/
  
          /*if ($field == "system" || $field == "browser" || $field == "issue" || $field == "multiple") {
              if ($value == "----" || $value == "") {
                  return 0;
              } else {
                  return 1;
              }
          }*/
  
      }
  
      if($_POST) {
  
          //'id','phone','course','instructor',
  
          $fields = array('name','title', 'date', 'time',  'building', 'room', 'location', 'occurrence','person', 'title1', 'phone1', 'explanation', 'security', 'police', 'witness', 'acttaken', 'followact');
          $x = 0 - 1;
  
          foreach($fields as $field) {
  
              if(isset($_POST[$field])) {
                  $validation = validate($field, $_POST[$field]);
                  if ($validation == 1) {
                      $x++;   
                      $info[$x] = $_POST[$field];
                  } else {
                      $problems[$field] = 1;
                      $showform = 1;
                  }
              } else {
                  $problems[$field] = 1;
                  $showform = 1;
              }
          }
  
      } else {
          $showform = 1;
      }
  
      if(count($problems) &lt; 1 &amp;&amp; $_POST) {
  
          // DO THE MAILING HERE
  
          $fields = array('title', 'name','date', 'time', 'building', 'room', 'location', 'title1','person',  'phone1', 'title2', 'person2', 'phone2','title3','person3',  'phone3','title4','person4',  'phone4','occurrence','obscene','altercation1', 'altercation2', 'sexharass', 'property', 'harm', 'drugs', 'other',  'explanation', 'security', 'police', 'witness','wtitle1', 'wperson',  'wphone1', 'wtitle2', 'wperson2', 'wphone2','wtitle3','wperson3',  'wphone3', 'acttaken', 'followact');
  
          //$to = "aabdelzaher@dacc.edu";
          $to2 = "aabdelzaher@dacc.edu";
          $to3 ="aabdelzaher@dacc.edu";
          $to4 = "aabdelzaher@dacc.edu";
          $to5 ="aabdelzaher@dacc.edu";
          $to6 = "aabdelzaher@dacc.edu";
          $to7 ="aabdelzaher@dacc.edu";
          $to8 = "aabdelzaher@dacc.edu";
          $to9 ="aabdelzaher@dacc.edu";
          $to10 ="aabdelzaher@dacc.edu";
  
          $subject = "Incident / Unusual Occurrence Report";
          $bound_text =   "DACCreport";
     $bound =     "--".$bound_text."\r\n";
     $bound_last =    "--".$bound_text."--\r\n";
     $headers =   "From: noreply@dacc.edu\r\n";
     $headers .=  "MIME-Version: 1.0\r\n"
  ."Content-Type: multipart/mixed; boundary=\"$bound_text\"".PHP_EOL;
  
  
  
     $file =  file_get_contents("report.csv");
  
  
          //$headers  ='MIME-Version: 1.0' .PHP_EOL;
          //$headers .='Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
          //$headers .= "From: noreply@dacc.edu\r\n" . "X-Mailer: php";
          $greet = "&lt;br&gt;The following was submitted on " . date("F j, Y, g:i a") . "&lt;p&gt;&lt;p&gt;";
      //  $greet .= "&lt;a href=http://www.dacc.edu/documents/report.csv&gt;report.csv&lt;/a&gt;";
          if(isset($_POST['sexharass']) &amp;&amp; is_array($_POST['sexharass']))             
          {$sexharass = implode('; ',$_POST['sexharass']);}
          if(isset($_POST['altercation1']) &amp;&amp; is_array($_POST['altercation1'])) {
          $altercation1 = implode('; ', $_POST['altercation1']);}
          if(isset($_POST['altercation2']) &amp;&amp; is_array($_POST['altercation2'])) {
          $altercation2 = implode('; ', $_POST['altercation2']);}
          if(isset($_POST['harm']) &amp;&amp; is_array($_POST['harm']))   
                  {$harm = implode('; ', $_POST['harm']);}
          if(isset($_POST['property']) &amp;&amp; is_array($_POST['property']))   
                  {$property = implode('; ', $_POST['property']); }
          if(isset($_POST['drugs']) &amp;&amp; is_array($_POST['drugs']))         
              {$drugs = implode('; ', $_POST['drugs']);}
          if(isset($_POST['other']) &amp;&amp; is_array($_POST['other']))     
                  {$other = implode('; ', $_POST['other']);}
  
          if(isset($_POST['sexharass']) &amp;&amp; is_array($_POST['sexharass']))             
                  {$sexharass2 = implode('; ',$_POST['sexharass']); } else {$sexharass2='N/A';}
          if(isset($_POST['altercation1']) &amp;&amp; is_array($_POST['altercation1'])) 
          {$altercation12 = implode('; ', $_POST['altercation1']);}else {$altercation12='N/A';}
  
          if(isset($_POST['altercation2']) &amp;&amp; is_array($_POST['altercation2'])) 
  
          {
          $altercation22 = implode('; ', $_POST['altercation2']);}else {$altercation22='N/A';}
  
          if(isset($_POST['harm']) &amp;&amp; is_array($_POST['harm']))   
                  {$harm2 = implode('; ', $_POST['harm']);}else {$harm2='N/A';}
  
          if(isset($_POST['property']) &amp;&amp; is_array($_POST['property']))   
                  {$property2 = implode('; ', $_POST['property']);    }else {$property2='N/A';}
  
          if(isset($_POST['drugs']) &amp;&amp; is_array($_POST['drugs']))         
              {$drugs2 = implode('; ', $_POST['drugs']);}else {$drugs2='N/A';}
  
          if(isset($_POST['other']) &amp;&amp; is_array($_POST['other']))     
                  {$other2 = implode('; ', $_POST['other']);}else {$other2='N/A';}
        if(isset($_POST['obscene']) &amp;&amp; is_array($_POST['obscene']))   
                  {$obscene = implode('; ', $_POST['obscene']);}else {$obscene='N/A';}
  
  
  
          $body =   $greet  ; 
  
   $name= $_POST['name'];
   $title= $_POST['title'];
   $titlename = "\"$title\"";
   $date= $_POST['date'];
   $date2 = "\"$date\"";
   $time= $_POST['time'];
   $building= $_POST['building'];
   $room= $_POST['room'];
  
   $location= $_POST['location'];
   $location2 = "\"$location\"";
   $person= $_POST['person'];
  
  $title1= $_POST['title1'];
   $title12 = "\"$title1\"";
   $phone1= $_POST['phone1'];
   if(isset($_POST['title2'])) {$title2= $_POST['title2']; } 
   $title22 = "\"$title2\"";
   if(isset($_POST['person2'])) {$person2= $_POST['person2']; } 
   if(isset($_POST['phone2'])) {$phone2= $_POST['phone2']; } 
   if(isset($_POST['title3'])) {$title3= $_POST['title3']; } 
   $title32 = "\"$title3\"";
   if(isset($_POST['person3'])) {$person3= $_POST['person3']; } 
   if(isset($_POST['phone3'])) {$phone3= $_POST['phone3']; } 
   if(isset($_POST['title4'])) {$title4= $_POST['title4']; } 
   $title42 = "\"$title4\"";
   if(isset($_POST['person4'])) {$person4= $_POST['person4']; } 
   if(isset($_POST['phone4'])) {$phone4= $_POST['phone4']; } 
   $explanation= $_POST['explanation'];
   $explanation2 = "\"$explanation\"";
   $security= $_POST['security'];
   $police= $_POST['police'];
   $witness= $_POST['witness'];
  
   if(isset($_POST['wtitle1'])) {$wtitle1= $_POST['wtitle1']; }
   $wtitle12 = "\"$wtitle1\"";
   if(isset($_POST['wperson'])) {$wperson= $_POST['wperson']; } 
   if(isset($_POST['wphone1'])) {$wphone1= $_POST['wphone1']; } 
   if(isset($_POST['wtitle2'])) {$wtitle2= $_POST['wtitle2']; } 
   $wtitle22 = "\"$wtitle2\"";
   if(isset($_POST['wperson2'])) {$wperson2= $_POST['wperson2']; } 
   if(isset($_POST['wphone2'])) {$wphone2= $_POST['wphone2']; } 
   if(isset($_POST['wtitle3'])) {$wtitle3= $_POST['wtitle3']; }
   $wtitle32 = "\"$wtitle3\""; 
   if(isset($_POST['wperson3'])) {$wperson3= $_POST['wperson3']; } 
   if(isset($_POST['wphone3'])) {$wphone3= $_POST['wphone3']; } 
   $acttaken= $_POST['acttaken'];
   $acttaken2 = "\"$acttaken\"";
   $followact= $_POST['followact'];
   $followact2 = "\"$followact\"";
  
      $csvData2 = " title ,  name , date ,  time ,  building ,  room ,  location ,  title1 , person ,   phone1 ,  title2 ,  person2 ,  phone2 , title3 , person3 ,   phone3 , title4 , person4 ,   phone4 , obscene , altercation1 ,  altercation2 ,  sexharass ,  property ,  harm ,  drugs ,  other ,   explanation ,  security ,  police ,  witness , wtitle1 ,  wperson ,   wphone1 ,  wtitle2 ,  wperson2 ,  wphone2 , wtitle3 , wperson3 ,   wphone3 ,  acttaken ,  followact" . "\n";
      $csvData = $titlename . "," . $name . "," . $date2 . "," . $time . "," . $building . "," . $room . "," . $location2 . "," .   $title12 . "," . $person . "," .  $phone1 . "," . $title22  . "," . $person2 . "," .  $phone2 . "," . $title32  . "," . $person3 . "," .  $phone3 . "," . $title42  . "," . $person4 . "," .  $phone4 . "," . $obscene . "," . $altercation12 . ","  . $altercation22 . ","  . $sexharass2."," .  $property2 . ","  . $harm2 . "," . $drugs2 . "," . $other2 . "," . $explanation2 . "," . $security . "," . $police . "," . $witness . "," . $wtitle12 . "," . $wperson . "," . $wphone1 . "," . $wtitle22 . "," . $wperson2 . "," . $wphone2 . "," . $wtitle32 . "," . $wperson3 . "," . $wphone3 . "," . $acttaken2 . "," . $followact2 . "\n";  
      $fp = fopen("report.csv","w"); 
  
          $cn = 1;
  
  
          foreach($fields as $efield) {
  
  
              if(isset($_POST[$efield])) {
  
  
                  if($efield == "occurrence") {
                  $body.= "&lt;strong&gt;". " Type of Occurrence: "."&lt;/strong&gt;&lt;p&gt;";
  
                      } elseif($efield == "obscene" ) {
                          $body.=  $_POST[$efield] . "&amp;nbsp; &lt;P&gt;";
                      } elseif($efield == "altercation1" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;em&gt;". " Altercation:&amp;nbsp;"."&lt;/em&gt;" . $altercation1 . "&amp;nbsp;- &amp;nbsp;";
                      } elseif($efield == "altercation2" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;". " "."&lt;/strong&gt;" . $altercation2 . " &amp;nbsp; &lt;p&gt; ";
                      } elseif($efield == "sexharass" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;em&gt;". " Sexual Harrasment: &amp;nbsp;"."&lt;/em&gt;" . $sexharass . "&amp;nbsp; &lt;p&gt;";
                      } elseif($efield == "property" &amp;&amp; $_POST[$efield] != '') {
                          $body.=   "&lt;em&gt;". "Damage to Property:&amp;nbsp; "."&lt;/em&gt;" . $property . "&amp;nbsp;&lt;p&gt;     ";
                      } elseif($efield == "harm" &amp;&amp; $_POST[$efield] != '') {
                          $body.=   "&lt;em&gt;". " Threat of Harm to Self or Others:&amp;nbsp; "."&lt;/em&gt;" . $harm                                                   ."&amp;nbsp;&lt;p&gt; ";
                      } elseif($efield == "drugs" &amp;&amp; $_POST[$efield] != '') {
                          $body.=   "&lt;em&gt;". " Drugs or Alcohol:&amp;nbsp; "."&lt;/em&gt;" . $drugs ."&amp;nbsp;&lt;p&gt; ";
                      } elseif($efield == "other" &amp;&amp; $_POST[$efield] != '') {
                          $body.=   "&lt;em&gt;". " Other types of Occurrences: &amp;nbsp;"."&lt;/em&gt;" . $other ."&amp;nbsp;&lt;p&gt; ";
  
  
                      } elseif($efield == "title") {
                          $body.= "&lt;strong&gt;"."Name of Person Filing Report: " ."&lt;/strong&gt;" . $_POST[$efield] .                                                    " ";
  
                      } elseif($efield == "name") {
                          $body.= "   " . $_POST[$efield] . "&lt;p&gt;&lt;hr color=' #33cc66'&gt;"  ;
  
                      } elseif($efield == "date") {
                          $body.= "&lt;strong&gt;". "Date of Occurrence: "."&lt;/strong&gt;". $_POST[$efield] . " &amp;nbsp;                                                      ";
                  /*  } elseif($efield == "day") {
                          $body.= "&lt;strong&gt;". " "."&lt;/strong&gt;" . $_POST[$efield] . ", &amp;nbsp;  ";
  
                      } elseif($efield == "year") {
                          $body.= "&lt;strong&gt;". " "."&lt;/strong&gt;" . $_POST[$efield] . " &amp;nbsp;  ";*/
  
                      } elseif ($efield == "time") {
                          $body.= "&lt;strong&gt;"."Time: " ."&lt;/strong&gt;". $_POST[$efield] . "&lt;/p&gt;";
                      } elseif ($efield == "building") {
                          $body.= "&lt;strong&gt;"."Building: ". "&lt;/strong&gt;" . $_POST[$efield] . " &amp;nbsp; &amp;nbsp;&amp;nbsp;                                                  &amp;nbsp;&amp;nbsp;  ";
                      } elseif ($efield == "room") {
                          $body.= "&lt;strong&gt;"."Room: "."&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;";
                      } elseif ($efield == "location") {
                          $body.= "&lt;strong&gt;"."Description of Location: ". "&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;                                                    &lt;hr color=' #33cc66'&gt;";
                      } elseif ($efield == "title1") {
                          $body.= "&lt;strong&gt;"."First Person involved: ". "&lt;/strong&gt;" . $_POST[$efield] . "&amp;nbsp;                                                   &amp;nbsp; ";
                      } elseif ($efield == "person") {
                          $body.= "&amp;nbsp;&amp;nbsp;&amp;nbsp;" . $_POST[$efield] . "&lt;p&gt;";
  
                      } elseif ($efield == "phone1") {
                          $body.= "&lt;strong&gt;". "Phone : ". "&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;&lt;hr color=' #                                                       33cc66'&gt;";
                      } elseif($efield == "title2" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;"."Second Person involved: ". "&lt;/strong&gt;" . $_POST[$efield] . "&amp;nbsp;                                                  &amp;nbsp; ";
                      } elseif($efield == "person2" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "  " . $_POST[$efield] . "&lt;p&gt; ";
                      } elseif($efield == "phone2" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;". "Phone : ". "&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;&lt;hr color=' #                                                       33cc66'&gt;";
                      } elseif($efield == "title3" &amp;&amp; $_POST[$efield] != '') {
                          $body.="&lt;strong&gt;". "Third Person involved: ". "&lt;/strong&gt;" . $_POST[$efield] . " &amp;nbsp;                                                  &amp;nbsp; ";
                      } elseif($efield == "person3" &amp;&amp; $_POST[$efield] != '') {
                          $body.= " &amp;nbsp;&amp;nbsp; " . $_POST[$efield] . "&lt;p&gt;";
  
                      } elseif($efield == "phone3" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;"."Phone: "."&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;&lt;hr color=' #                                                          33cc66'&gt;";
                      } elseif($efield == "title4" &amp;&amp; $_POST[$efield] != '') {
                          $body.="&lt;strong&gt;". "Fourth Person Involved: ". "&lt;/strong&gt;" . $_POST[$efield] . "                                                        &amp;nbsp;&amp;nbsp; ";
                      } elseif($efield == "person4" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&amp;nbsp;&amp;nbsp; " . $_POST[$efield] . "&lt;p&gt;";
                      } elseif($efield == "phone4" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;"."Phone: ". "&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;&lt;hr color=' #                                                         33cc66'&gt;";
                      } elseif ($efield == "explanation") {
                          $body.= "&lt;strong&gt;"."Detailed Explanation: ". "&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;&lt;hr                                                        color=' #33cc66'&gt;";
                      } elseif ($efield == "security") {
                          $body.= "&lt;strong&gt;"."Security called: ". "&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;";
                      } elseif ($efield == "police") {
                          $body.= "&lt;strong&gt;"."Police called: "."&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;";
                      } elseif ($efield == "witness") {
                          $body.= "&lt;strong&gt;"."Were there witnesses: "."&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;&lt;hr                                                     color=' #33cc66'&gt;";
                      } elseif($efield == "wtitle1" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;"."Witness: "."&lt;/strong&gt;" . $_POST[$efield] . "&amp;nbsp;&amp;nbsp; ";
                      } elseif($efield == "wperson" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&amp;nbsp;&amp;nbsp;" . $_POST[$efield] . "&lt;p&gt;";
                      } elseif($efield == "wphone1" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;"."Phone : "."&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;&lt;hr color=' #                                                         33cc66'&gt;";
                       }elseif($efield == "wtitle2" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;"."Second witness: ". "&lt;/strong&gt;" . $_POST[$efield] . "&amp;nbsp;&amp;nbsp;                                                    ";
                      } elseif($efield == "wperson2" &amp;&amp; $_POST[$efield] != '') {
                          $body.= " &amp;nbsp;&amp;nbsp; " . $_POST[$efield] . "&lt;p&gt;";
                      } elseif($efield == "wphone2" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;"."Phone : ". "&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;&lt;hr color=' #                                                        33cc66'&gt;";
  
                      } elseif($efield == "wtitle3" &amp;&amp; $_POST[$efield] != '') {
                          $body.="&lt;strong&gt;". "Third witness: ". "&lt;/strong&gt;" . $_POST[$efield] . " &amp;nbsp;&amp;nbsp;                                                    ";
                      } elseif($efield == "wperson3" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&amp;nbsp;&amp;nbsp;  " . $_POST[$efield] . "&lt;p&gt;";
  
                      } elseif($efield == "wphone3" &amp;&amp; $_POST[$efield] != '') {
                          $body.= "&lt;strong&gt;". "Phone: "."&lt;/strong&gt;" . $_POST[$efield] . "&lt;p&gt;&lt;hr color=' #                                                         33cc66'&gt;";
                      } elseif ($efield == "acttaken") {
                          $body.= "&lt;strong&gt;"."Immediate Action Taken: " ."&lt;/strong&gt;". $_POST[$efield] . "&lt;p&gt;&lt;hr                                                   color=' #33cc66'&gt;";
                      } elseif ($efield == "followact") {
                          $body.= "&lt;strong&gt;". "What Follow-up Action will be taken: " ."&lt;/strong&gt;".                                                               $_POST[$efield] . "&lt;p&gt;&lt;hr color=' #33cc66'&gt;";
  
  
   if($fp){
  
   fwrite($fp,$csvData2);
   fwrite($fp,$csvData); // Write information to the file
   fclose($fp); // Close the file
  
   }}
              }
          }
  $message =  "If you can see this MIME than your client doesn't accept MIME types!\r\n"
  .$bound;
  
   $message .=    "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
  ."Content-Transfer-Encoding: 7bit\r\n\r\n"
  ."Here is the report.csv you requested\r\n"  .$body ."\r\n"
  .$bound;
  
   $message .=    "Content-Type: text/csv; name=\"report.csv\"\r\n"
  ."Content-Transfer-Encoding: base64\r\n"
  ."Content-disposition: attachment; file=\"report.csv\"\r\n"
  ."\r\n"
  .chunk_split(base64_encode($file))
  .$bound_last; 
  
          //  mail($to, $subject,$message , $headers);
          mail($to2, $subject,$message , $headers);
          mail($to3, $subject,$message , $headers);
          mail($to4, $subject,$message , $headers);
          mail($to5, $subject,$message , $headers);
          mail($to6, $subject,$message , $headers);
          mail($to7, $subject,$message , $headers);
          mail($to8, $subject,$message , $headers);
          mail($to9, $subject,$message , $headers);
              mail($to10, $subject,$message , $headers);
          ?&gt;
  
  
  
          &lt;p class="style1"&gt;Your report has been submitted.&lt;br&gt;&lt;br&gt;&lt;/p&gt;
          &lt;?php
  
      }
  
      if($showform == 1) {
  if(count($problems) &gt; 0) { ?&gt;
      &lt;p&gt;&lt;strong&gt;&lt;font color="red"&gt;PLEASE CORRECT ANY FIELDS WITH A RED * BY 
      THEM&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;?php } 
  
     }
     ?&gt;
  </code></pre>