如何在PHP程序中跟踪“解析错误:语法错误”?

时间:2017-06-07 03:55:48

标签: php

我尝试过repl,linter并且找不到遗漏的东西。我是PHP的新手。

  

错误:解析错误:语法错误,第62行意外的$ end

'第62行'是最后一行代码,它是我网站的电子邮件表单

代码:

<?php
if(isset($_POST['email'])) {


   $email_to = "(my email is in here)";
   $email_subject = "Enquiry";



   // validation expected data exists
   if(!isset($_POST['first_name']) ||
       !isset($_POST['email']) ||
       !isset($_POST['comments'])) {
       died('We are sorry, but there appears to be a problem with the form you submitted.');
   }

   $first_name = $_POST['first_name']; // required

   $email_from = $_POST['email']; // required
   $comments = $_POST['comments']; // required

   $error_message = "";
   $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 if(!preg_match($email_exp,$email_from)) {
   $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 }
   $string_exp = "/^[A-Za-z\s.'-]+$/";
 if(!preg_match($string_exp,$first_name)) {
   $error_message .= 'The First Name you entered does not appear to be valid.<br />';
 }

 if(strlen($comments) < 2) {
   $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 }
 if(strlen($error_message) > 0) {
   died($error_message);
 }
   $email_message = "Details below.\n\n";

   function clean_string($string) {
     $bad = array("content-type","bcc:","to:","cc:","href");
     return str_replace($bad,"",$string);
   }

   $email_message .= "First Name: ".clean_string($first_name)."\n";

   $email_message .= "Email: ".clean_string($email_from)."\n";
   $email_message .= "Comments: ".clean_string($comments)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_to."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
sleep(1);
echo "<meta http-equiv='refresh' content=\"0; url=http://kahlilashanti.com">";
?>

<?php
}
?>-->

2 个答案:

答案 0 :(得分:2)

你在行尾的内容末尾的双引号上无法逃脱:

echo "<meta http-equiv='refresh' content=\"0; url=http://kahlilashanti.com">";

应该是

echo "<meta http-equiv='refresh' content=\"0; url=http://kahlilashanti.com\">";

答案 1 :(得分:1)

你在脚本结束时错过了'}'。您开始条件if(isset($_POST['email'])) {但未关闭它。