0

我已经在 SO 上搜索了一个多小时,但无法解决我的问题。由于某种原因,第 262 行中的 Parse Error: syntax error unexpected } 在页面上出现错误。它是 else 条件的右括号。

我删除了其他条件,代码运行顺利。然后我恢复并删除了其他条件内的所有内容,但错误仍然相同,我很困惑为什么右括号是意外的。

这是代码

if(isset($_POST['sendEmailNotification'])){

$keyword = $_POST['sendEmailNotification'];
$sql = "SELECT * FROM team where keyword = '$keyword'" ;
$sql_result = mysqli_query($conn,$sql) or die (mysqli_error($conn));
while ($row = mysqli_fetch_assoc($sql_result)){
    $abcd = $row; 
} 

$htmlContent = file_get_contents ("email_template_header.php"); 
$registerURL = $siteURL.'/register/';

if ($abcd['claimed'] == 1) {

    $htmlContent .= "<p>Hey,</p>";
    $htmlContent .= "<p>Hope you're doing well!!!</p>";
    $htmlContent .= "<p>Someone has submitted an image related to your business on www.trustedbusiness.reviews. He/She might be your customer or may be your employee/ex-employee.</p>";
    $htmlContent .= "<p>You can approve the image just by following these simple steps:</p>";
    $htmlContent .= "<ol>";
    $htmlContent .= "<li>View Business Center</li>";
    $htmlContent .= "<li>Click on Business Name</li>";
    $htmlContent .= "<li>Select 'Image' option from sidebar</li>";
    $htmlContent .= "<li>Approve the 'Image' & you're done</li>";
    $htmlContent .= "</ol>";
    $htmlContent .= "<p>If you need any help or have any suggestions to make the User Experience better. Please feel free to contact Trusted Business Reviews team.</p>";
    $htmlContent .= "<p>Thanks</p>";

}
else {

    $htmlContent .= "<p>Hey,</p>";
    $htmlContent .= "<p>Hope you're doing well!!!</p>";
    $htmlContent .= "<p>Someone has submitted an image related to your business on www.trustedbusiness.reviews. He/She might be your customer or maybe your employee/ex-employee.</p>";
    $htmlContent .= "<p>Uh-oh!</p>";
    $htmlContent .= "<p>You haven't claimed your business on Trusted Business Reviews? No problem!</p>";
    $htmlContent .= "<p>You can claim this by following these simple & super easy steps:</p>";
    $htmlContent .= "<ol>";
    $htmlContent .= "<li>Register here</li>";
    $htmlContent .= "<li>Open your Business Listing Page</li>";
    $htmlContent .= "<li>Click on 'Claim This Business'</li>";
    $htmlContent .= "<li>Enter your domain email address</li>";
    $htmlContent .= "<li>Enter Verification Code</li>";
    $htmlContent .= "<li>You're Done</li>";

    $htmlContent .= "</ol>";
    $htmlContent .= "<p>You can make the desired changes in the information (if needed) after 'claim this business' process.</p>";
    $htmlContent .= "<p>Later, You can approve the image just by following these simple steps:</p>";
    $htmlContent .= "<ol>";
    $htmlContent .= "<li>View Business Center</li>";
    $htmlContent .= "<li>Click on Business Name</li>";
    $htmlContent .= "<li>Select 'Image' option from sidebar</li>";
    $htmlContent .= "<li>Approve the 'Image' & you're done</li>";
    $htmlContent .= "</ol>";
    $htmlContent .= "<p>If you need any help or have any suggestions to make the User Experience better. Please feel free to contact Trusted Business Reviews team.</p>";
    $htmlContent .= "<p>Thanks</p>";
}
$htmlContent .= file_get_contents ("email_template_footer.php"); 
$to = $abcd['b_email'];

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->setFrom('abc@mail.com', 'ABC');
$mail->addAddress($to);
$mail->isHTML(true);
$mail->Subject = 'New Image Uploaded';
$mail->Body = $htmlContent;
$mail->send();
$mail->clearAddresses();
}
4

1 回答 1

2

作为可能的答案,没有足够的评论点:

当我的代码(如您的)很好时,我遇到了一连串神秘的“解析错误”。

在我的情况下,它是由我的电脑(操作系统/浏览器?)在从网页复制和粘贴示例代码期间以某种方式插入的虚假隐藏字符引起的。

例如else {

如果“else”和“{”之间的“空格”实际上不是“空格”,那么它可能会导致后续{被忽略。结果:else 语句的提前终止,即else $htmlContent .= "<p>Hey,</p>";您的连接的其余部分将被视为 else 块之外的语句,而结束的“}”则无效。

尝试删除 else 子句并手动重​​新键入。

如果这不起作用,请在设置为显示隐藏字符的编辑器中打开您的代码。在 HTML 工具包中(我认为)view->editor->hidden characters会将这些字符显示为纯黑色,而不是纯白色的空格。

于 2017-10-06T08:22:03.513 回答