0

我需要一些帮助,我正在尝试向页面添加验证码,但在此代码的最后一行出现意外的 $end 错误,我无法弄清楚我犯错的原因或位置。顺便说一句,我没有在这里包含私钥,但它在我的代码中。

<?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->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->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) < 1 && $_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 = "<br>The following was submitted on " . date("F j, Y, g:i a") . "<p><p>";
    //  $greet .= "<a href=http://www.dacc.edu/documents/report.csv>report.csv</a>";
        if(isset($_POST['sexharass']) && is_array($_POST['sexharass']))             
        {$sexharass = implode('; ',$_POST['sexharass']);}
        if(isset($_POST['altercation1']) && is_array($_POST['altercation1'])) {
        $altercation1 = implode('; ', $_POST['altercation1']);}
        if(isset($_POST['altercation2']) && is_array($_POST['altercation2'])) {
        $altercation2 = implode('; ', $_POST['altercation2']);}
        if(isset($_POST['harm']) && is_array($_POST['harm']))   
                {$harm = implode('; ', $_POST['harm']);}
        if(isset($_POST['property']) && is_array($_POST['property']))   
                {$property = implode('; ', $_POST['property']); }
        if(isset($_POST['drugs']) && is_array($_POST['drugs']))         
            {$drugs = implode('; ', $_POST['drugs']);}
        if(isset($_POST['other']) && is_array($_POST['other']))     
                {$other = implode('; ', $_POST['other']);}

        if(isset($_POST['sexharass']) && is_array($_POST['sexharass']))             
                {$sexharass2 = implode('; ',$_POST['sexharass']); } else {$sexharass2='N/A';}
        if(isset($_POST['altercation1']) && is_array($_POST['altercation1'])) 
        {$altercation12 = implode('; ', $_POST['altercation1']);}else {$altercation12='N/A';}

        if(isset($_POST['altercation2']) && is_array($_POST['altercation2'])) 

        {
        $altercation22 = implode('; ', $_POST['altercation2']);}else {$altercation22='N/A';}

        if(isset($_POST['harm']) && is_array($_POST['harm']))   
                {$harm2 = implode('; ', $_POST['harm']);}else {$harm2='N/A';}

        if(isset($_POST['property']) && is_array($_POST['property']))   
                {$property2 = implode('; ', $_POST['property']);    }else {$property2='N/A';}

        if(isset($_POST['drugs']) && is_array($_POST['drugs']))         
            {$drugs2 = implode('; ', $_POST['drugs']);}else {$drugs2='N/A';}

        if(isset($_POST['other']) && is_array($_POST['other']))     
                {$other2 = implode('; ', $_POST['other']);}else {$other2='N/A';}
      if(isset($_POST['obscene']) && 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.= "<strong>". " Type of Occurrence: "."</strong><p>";

                    } elseif($efield == "obscene" ) {
                        $body.=  $_POST[$efield] . "&nbsp; <P>";
                    } elseif($efield == "altercation1" && $_POST[$efield] != '') {
                        $body.= "<em>". " Altercation:&nbsp;"."</em>" . $altercation1 . "&nbsp;- &nbsp;";
                    } elseif($efield == "altercation2" && $_POST[$efield] != '') {
                        $body.= "<strong>". " "."</strong>" . $altercation2 . " &nbsp; <p> ";
                    } elseif($efield == "sexharass" && $_POST[$efield] != '') {
                        $body.= "<em>". " Sexual Harrasment: &nbsp;"."</em>" . $sexharass . "&nbsp; <p>";
                    } elseif($efield == "property" && $_POST[$efield] != '') {
                        $body.=   "<em>". "Damage to Property:&nbsp; "."</em>" . $property . "&nbsp;<p>     ";
                    } elseif($efield == "harm" && $_POST[$efield] != '') {
                        $body.=   "<em>". " Threat of Harm to Self or Others:&nbsp; "."</em>" . $harm                                                   ."&nbsp;<p> ";
                    } elseif($efield == "drugs" && $_POST[$efield] != '') {
                        $body.=   "<em>". " Drugs or Alcohol:&nbsp; "."</em>" . $drugs ."&nbsp;<p> ";
                    } elseif($efield == "other" && $_POST[$efield] != '') {
                        $body.=   "<em>". " Other types of Occurrences: &nbsp;"."</em>" . $other ."&nbsp;<p> ";


                    } elseif($efield == "title") {
                        $body.= "<strong>"."Name of Person Filing Report: " ."</strong>" . $_POST[$efield] .                                                    " ";

                    } elseif($efield == "name") {
                        $body.= "   " . $_POST[$efield] . "<p><hr color=' #33cc66'>"  ;

                    } elseif($efield == "date") {
                        $body.= "<strong>". "Date of Occurrence: "."</strong>". $_POST[$efield] . " &nbsp;                                                      ";
                /*  } elseif($efield == "day") {
                        $body.= "<strong>". " "."</strong>" . $_POST[$efield] . ", &nbsp;  ";

                    } elseif($efield == "year") {
                        $body.= "<strong>". " "."</strong>" . $_POST[$efield] . " &nbsp;  ";*/

                    } elseif ($efield == "time") {
                        $body.= "<strong>"."Time: " ."</strong>". $_POST[$efield] . "</p>";
                    } elseif ($efield == "building") {
                        $body.= "<strong>"."Building: ". "</strong>" . $_POST[$efield] . " &nbsp; &nbsp;&nbsp;                                                  &nbsp;&nbsp;  ";
                    } elseif ($efield == "room") {
                        $body.= "<strong>"."Room: "."</strong>" . $_POST[$efield] . "<p>";
                    } elseif ($efield == "location") {
                        $body.= "<strong>"."Description of Location: ". "</strong>" . $_POST[$efield] . "<p>                                                    <hr color=' #33cc66'>";
                    } elseif ($efield == "title1") {
                        $body.= "<strong>"."First Person involved: ". "</strong>" . $_POST[$efield] . "&nbsp;                                                   &nbsp; ";
                    } elseif ($efield == "person") {
                        $body.= "&nbsp;&nbsp;&nbsp;" . $_POST[$efield] . "<p>";

                    } elseif ($efield == "phone1") {
                        $body.= "<strong>". "Phone : ". "</strong>" . $_POST[$efield] . "<p><hr color=' #                                                       33cc66'>";
                    } elseif($efield == "title2" && $_POST[$efield] != '') {
                        $body.= "<strong>"."Second Person involved: ". "</strong>" . $_POST[$efield] . "&nbsp;                                                  &nbsp; ";
                    } elseif($efield == "person2" && $_POST[$efield] != '') {
                        $body.= "  " . $_POST[$efield] . "<p> ";
                    } elseif($efield == "phone2" && $_POST[$efield] != '') {
                        $body.= "<strong>". "Phone : ". "</strong>" . $_POST[$efield] . "<p><hr color=' #                                                       33cc66'>";
                    } elseif($efield == "title3" && $_POST[$efield] != '') {
                        $body.="<strong>". "Third Person involved: ". "</strong>" . $_POST[$efield] . " &nbsp;                                                  &nbsp; ";
                    } elseif($efield == "person3" && $_POST[$efield] != '') {
                        $body.= " &nbsp;&nbsp; " . $_POST[$efield] . "<p>";

                    } elseif($efield == "phone3" && $_POST[$efield] != '') {
                        $body.= "<strong>"."Phone: "."</strong>" . $_POST[$efield] . "<p><hr color=' #                                                          33cc66'>";
                    } elseif($efield == "title4" && $_POST[$efield] != '') {
                        $body.="<strong>". "Fourth Person Involved: ". "</strong>" . $_POST[$efield] . "                                                        &nbsp;&nbsp; ";
                    } elseif($efield == "person4" && $_POST[$efield] != '') {
                        $body.= "&nbsp;&nbsp; " . $_POST[$efield] . "<p>";
                    } elseif($efield == "phone4" && $_POST[$efield] != '') {
                        $body.= "<strong>"."Phone: ". "</strong>" . $_POST[$efield] . "<p><hr color=' #                                                         33cc66'>";
                    } elseif ($efield == "explanation") {
                        $body.= "<strong>"."Detailed Explanation: ". "</strong>" . $_POST[$efield] . "<p><hr                                                        color=' #33cc66'>";
                    } elseif ($efield == "security") {
                        $body.= "<strong>"."Security called: ". "</strong>" . $_POST[$efield] . "<p>";
                    } elseif ($efield == "police") {
                        $body.= "<strong>"."Police called: "."</strong>" . $_POST[$efield] . "<p>";
                    } elseif ($efield == "witness") {
                        $body.= "<strong>"."Were there witnesses: "."</strong>" . $_POST[$efield] . "<p><hr                                                     color=' #33cc66'>";
                    } elseif($efield == "wtitle1" && $_POST[$efield] != '') {
                        $body.= "<strong>"."Witness: "."</strong>" . $_POST[$efield] . "&nbsp;&nbsp; ";
                    } elseif($efield == "wperson" && $_POST[$efield] != '') {
                        $body.= "&nbsp;&nbsp;" . $_POST[$efield] . "<p>";
                    } elseif($efield == "wphone1" && $_POST[$efield] != '') {
                        $body.= "<strong>"."Phone : "."</strong>" . $_POST[$efield] . "<p><hr color=' #                                                         33cc66'>";
                     }elseif($efield == "wtitle2" && $_POST[$efield] != '') {
                        $body.= "<strong>"."Second witness: ". "</strong>" . $_POST[$efield] . "&nbsp;&nbsp;                                                    ";
                    } elseif($efield == "wperson2" && $_POST[$efield] != '') {
                        $body.= " &nbsp;&nbsp; " . $_POST[$efield] . "<p>";
                    } elseif($efield == "wphone2" && $_POST[$efield] != '') {
                        $body.= "<strong>"."Phone : ". "</strong>" . $_POST[$efield] . "<p><hr color=' #                                                        33cc66'>";

                    } elseif($efield == "wtitle3" && $_POST[$efield] != '') {
                        $body.="<strong>". "Third witness: ". "</strong>" . $_POST[$efield] . " &nbsp;&nbsp;                                                    ";
                    } elseif($efield == "wperson3" && $_POST[$efield] != '') {
                        $body.= "&nbsp;&nbsp;  " . $_POST[$efield] . "<p>";

                    } elseif($efield == "wphone3" && $_POST[$efield] != '') {
                        $body.= "<strong>". "Phone: "."</strong>" . $_POST[$efield] . "<p><hr color=' #                                                         33cc66'>";
                    } elseif ($efield == "acttaken") {
                        $body.= "<strong>"."Immediate Action Taken: " ."</strong>". $_POST[$efield] . "<p><hr                                                   color=' #33cc66'>";
                    } elseif ($efield == "followact") {
                        $body.= "<strong>". "What Follow-up Action will be taken: " ."</strong>".                                                               $_POST[$efield] . "<p><hr color=' #33cc66'>";


 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);
        ?>



        <p class="style1">Your report has been submitted.<br><br></p>
        <?php

    }

    if($showform == 1) {
if(count($problems) > 0) { ?>
    <p><strong><font color="red">PLEASE CORRECT ANY FIELDS WITH A RED * BY 
    THEM</font></strong></p>
<?php } 

   }
   ?>
4

1 回答 1

0

我发现我实际上从某个地方丢失了两个 }}

于 2013-07-22T14:45:55.647 回答