-4

我正在努力弄清楚为什么我的网站上的联系表格不起作用......

当我填写表格所需的信息并发送时,我得到的只是一个空白页面,URL 中有“ http://www.pinkpigdesign.co.uk/php/mail_form.php ”。转发电子邮件地址工作正常。

两个代码都直接来自模板。

我的html代码:

    <form class="required-form" action="php/mail_form.php"  method="POST">
    <ol class="forms">

    <li><label for="first_name"><em class="required">*</em> First Name</label>
    <input type="text" name="first_name" id="first_name" class="required"></li>

    <li><label for="last_name"><em class="required">*</em> Last Name</label>
    <input type="text" name="last_name" id="last_name" class="required"></li>

    <li><label for="telephone">Telephone</label>
    <input type="text" name="telephone" id="telephone"></li>

    <li><label for="email"><em class="required">*</em> Email</label>
    <input type="text" name="email" id="email" class="required"></li>

    <li><label for="message"><em class="required">*</em> Message</label>
    <textarea name="message" id="message" class="required" cols="45" rows="5"></textarea></li>

<li class="buttons submit"><button type="submit">Submit</button></li>

</ol>

我的PHP代码:

$yourEmail = "enquiries@pinkpigdesign.co.uk"; 
$yourWebsite = "www.pinkpigdesin.co.uk"; 
$thanksPage = 'thankyou.html'; 
$maxPoints = 4; 
$error_msg = null;
$result = null;

function isBot() {
$bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot");

$isBot = false;
foreach ($bots as $bot)
if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
    $isBot = true;

if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
    $isBot = true;

exit("Bots not allowed.</p>");
}

foreach ($badwords as $word)
    if (strpos($_POST['comments'], $word) !== false)
        $points += 2;

foreach ($exploits as $exploit)
    if (strpos($_POST['comments'], $exploit) !== false)
        $points += 2;

if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false)
    $points += 2;
if (isset($_POST['nojs']))
    $points += 1;
if (preg_match("/(<.*>)/i", $_POST['comments']))
    $points += 2;
if (strlen($_POST['name']) < 3)
    $points += 1;
if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500))
    $points += 2;

foreach ($_POST as $key => $value)
    $_POST[$key] = trim($value);

if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) {
    $error_msg .= "Name, e-mail and comments are required fields. \n";
} elseif (strlen($_POST['name']) > 15) {
    $error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n";
} elseif (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name']))) {
    $error_msg .= "The name field must not contain special characters. \n";
} elseif (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) {
    $error_msg .= "That is not a valid e-mail address. \n";
} elseif (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url']))
    $error_msg .= "Invalid website url.";

if ($error_msg == NULL && $points <= $maxPoints) {
    $subject = "Automatic Form Email";

    $message = "You received this e-mail message through your website: \n\n";
    foreach ($_POST as $key => $val) {
        $message .= ucwords($key) . ": " . clean($val) . "\r\n";
    }
    $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
    $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
    $message .= 'Points: '.$points;

    if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
        $headers   = "From: $yourEmail \r\n";
        $headers  .= "Reply-To: {$_POST['email']}";
    } else {
        $headers   = "From: $yourWebsite <$yourEmail> \r\n";
        $headers  .= "Reply-To: {$_POST['email']}";
    }

    if (mail($yourEmail,$subject,$message,$headers)) {
        if (!empty($thanksPage)) {
            header("Location: $thanksPage");
            exit;
        } else {
            $result = 'Your mail was successfully sent.';
        }
    } else {
        $error_msg = 'Your mail could not be sent this time.';
    }
} else {
    if (empty($error_msg))
        $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';
}
    }
function get_data($var) {
if (isset($_POST[$var]))
    echo htmlspecialchars($_POST[$var]);
}

我可能看不到错误,所以我希望有人能对这个问题有所了解......干杯!

4

1 回答 1

0

当期望一些输出(任何东西)“通常”时,一个空白页面表示 PHP 错误,因此脚本停止并且没有输出。您真的需要访问您的错误日志并查看它在开发时返回的内容,或者在开发时将它们发布到页面。

这是一个简单的问题,我将其推送到我的开发区为我在我的 PHP 错误日志中提供了您的问题的答案:

PHP Parse 错误:语法错误,第 89 行的 sites/site1/test.php 中出现意外的“}”

} else {
    if (empty($error_msg))
        $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';
}
    } //This shouldn't be here..?

删除不需要的},然后重试。

另外,为什么要混合使用带和不带花括号的 IF?{ }
你应该坚持一个并保持你的代码始终一致。有或没有(以及其他论点)这是个人选择,我个人总是使用它们。
对他们来说,体面的编辑器(我使用 vim)使用括号突出显示,当您单击括号或括号时,编辑器将突出显示配对的一个(打开或关闭)。

例如,当我在我的 Vim 中单击您的代码并单击不需要的大括号时,它不会突出显示另一个,因此显示没有对,因此它是独立的。

于 2013-08-29T16:58:55.360 回答