我有一个带有 recaptcha 的联系表,我正在尝试设置它,但在输入信息并单击提交按钮时会产生 500 错误。我敢打赌我做了一些愚蠢的事情,因为我不是 PHP 方面的佼佼者,所以如果我在这里发布我的代码,任何人都能够发现任何错误吗?
这是联系表本身。
<form class="email" action="mailer.php" method="post">
<p>Name:</p>
<input type="text" name="name" />
<p>E-mail:</p>
<input type="text" name="email" />
<p>Subject:</p>
<input type="text" name="subject" />
<p>Message:</p>
<textarea name="message"></textarea></p>
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6Le8_t4SAAAAACIxacT6Xn8NVvDa93loylG-L6mk"></script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=PUBLICKEYGOESHERE" height="300" width="500" frameborder="0"></iframe>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
</noscript>
<input class="send" type="submit" value="Send">
</form>
这是mailer.php
<?php
require_once('recaptchalib.php');
if ($_POST['email'] != '')
{
$privatekey = "6Le8_t4SAAAAAME8kuqO1bvzcSWmGytwISUYLo3w";
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid)
{
die("The reCAPTCHA wasn't entered correctly.
Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")");
}
else
{
/* Set e-mail recipient */
$myemail = "mandy@smarterbookkeeping.com.au";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$subject = check_input($_POST['subject'], "Enter a subject");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Write your message");
$captcha = check_input($_POST['captcha']);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
E-mail: $email
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: thanks.php');
exit();
/* Functions we used */
function check_input($data, $problem = '')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php
echo $myError;
?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
}
}
?>
我将recaptchalib 放在正确的位置,thanks.php 也是如此。我不是很擅长 PHP,但是这个让我很难过。