PHP解析错误:语法错误;文件的意外结束



尝试使用此PHP设置网页。我首先获得了空白页,然后将其显示为内部服务器错误的错误。经过一番研究,我发现主要是代码引起问题的代码。如果有人友好地寻找任何可能的解决方案,我将不胜感激。在此之前,还有更多的HTML代码,尽管它不包括任何PHP。

    <?php
$subjectPrefix = 'Site Contact Request';
$emailTo = '***@****.com';
if($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name     = stripslashes(trim($_POST['form-name']));
    $email    = stripslashes(trim($_POST['form-email']));
    $tel      = stripslashes(trim($_POST['form-tel']));
    $assunto  = stripslashes(trim($_POST['form-assunto']));
    $mensagem = stripslashes(trim($_POST['form-mensagem']));
    $pattern  = '/[rn]|Content-Type:|Bcc:|Cc:/i';
    if (preg_match($pattern, $name) || preg_match($pattern, $email) || preg_match($pattern, $assunto)) {
        die("Header injection detected");
    }
    $emailIsValid = preg_match('/^[^0-9][A-z0-9._%+-]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/', $email);
    if($name && $email && $emailIsValid && $assunto && $mensagem){
        $subject = "$subjectPrefix";
        $body = "Name: $name <br /> Subject: $assunto <br /> Email Address: $email <br /> Telephone Number: $tel <br /> Message: $mensagem";
        $headers  = 'MIME-Version: 1.1' . PHP_EOL;
        $headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
        $headers .= "From: $name <$email>" . PHP_EOL;
        $headers .= "Return-Path: $emailTo" . PHP_EOL;
        $headers .= "Reply-To: $email" . PHP_EOL;
        $headers .= "X-Mailer: PHP/". phpversion() . PHP_EOL;
        mail($emailTo, $subject, $body, $headers);
        $emailSent = true;
    } else {
        $hasError = true;
    }
}
?>
    <?php if(isset($emailSent) && $emailSent): ?>
        <div class="col-md-6 col-md-offset-3">
            <div class="alert alert-success text-center">Your message has been sent.</div>
        </div>
    <?php else: ?>
        <?php if(isset($hasError) && $hasError): ?>
        <div class="col-md-5 col-md-offset-4">
            <div class="alert alert-danger text-center">An error occurred. Please try later.</div>
        </div>
        <?php endif; ?>
    <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" id="contact-form" class="comment_form" role="form" method="post">
        <div class="row-fluid">
            <div class="span6">
                <input type="text" class="form-control" id="form-name" name="form-name" placeholder="Name" required>
            </div>
            <div class="span6">
                <input type="email" class="form-control" id="form-email" name="form-email" placeholder="Email" required>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span6">
                <input type="tel" class="form-control" id="form-tel" name="form-tel" placeholder="Telephone (Optional)">
            </div>
            <div class="span6">
                <input type="text" class="form-control" id="form-assunto" name="form-assunto" placeholder="Subject" required>
            </div>
        </div>
        <div class="row-fluid">
            <div class="span8">
                <textarea id="form-mensagem" name="form-mensagem" placeholder="Message"></textarea>
            </div>
            <div class="span4">
                <button class="btn" type="submit"><i class="li_paperplane"></i>Send message</button>
            </div>
        </div>
    </form>

您不会关闭一个条件,请这样修改: -

<?php if(isset($emailSent) && $emailSent): ?>
        <div class="col-md-6 col-md-offset-3">
            <div class="alert alert-success text-center">Your message has been sent.</div>
        </div>
    <?php else: ?>
        <?php if(isset($hasError) && $hasError): ?>
        <div class="col-md-5 col-md-offset-4">
            <div class="alert alert-danger text-center">An error occurred. Please try later.</div>
        </div>
        <?php endif; ?>
        <?php endif; ?> // this is missing and based on your functionality you can move it to anywhere else

输出:-http://prntscr.com/74n8d3

注意: - 这是第一个html启动的IF条件。取决于您的功能,您需要在任何需要的地方对其进行调整。

相关内容

  • 没有找到相关文章

最新更新