我試過repl,linter,找不到缺失的東西。我是PHP新手。如何在PHP程序中跟蹤「解析錯誤:語法錯誤」?
Error:Parse error: syntax error, unexpected $end on line 62
「線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._%-][email protected][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
}
?>-->
您發佈的代碼,而變量$'甚至提到,在這一點上任何人都無法做出幫助。 – Enstage
除了我們無法幫助您的語法錯誤之外,您的腳本還存在嚴重的安全問題。毫無疑問,它會被垃圾郵件劫持。任何人都可以通過腳本發送任何他們想要的東西。此外,您的電子郵件正則表達式還不夠好......您不能認爲頂級域名將會有2-4個字符......並且假定它不是像「房地產經紀人」這樣的TLD。 – Brad
僅供參考 - 基於下面的答案,它似乎已經從「意外的文件結束」到「意外的$結束」之類的錯誤消息... – Enstage