我正在努力將reCAPTCHA實現爲聯繫表&我一直無法弄清楚我做錯了什麼。 reCAPTCHA字段沒有顯示在頁面&它已經刪除我的PHP頁腳包括以及提交/重置按鈕。另外,我不確定是否在我的send-mail.php文件中正確執行驗證。PHP reCAPHTCHA,完全丟失
聯繫表
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
<link rel="icon" href="/bp/images/favicon.ico" type="image/x-icon" />
<title>San Diego Ministries | 3223232323.com</title>
<meta name="keywords" content="Jesus Christ, Ministries, Salvation, Church San Diego, Small Group, Christian" />
<meta name="description" content="... is a San Diego based Ministry." />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var RecaptchaOptions = {
theme : 'clean'
};
</script>
<!--/ CSS-->
<!--/ Events CSS-->
<link rel="stylesheet" href="/bp/css/prayer-request.css" type="text/css" media="screen" />
</head>
<body>
<?php include 'header.php'; ?>
<!--/ Title-->
<div class="prayer-title"><img src="/bp/images/prayer-title.jpg"></img></div>
<!--/ Prayer Request Description-->
<div id="prayer-desc">
<p>
If you have a prayer request or question for one of our pastors, fill out the form below and one of our pastors will receive it and personally pray for you.
Thanks for sharing and giving us the opportunity to pray for you!
</p>
<p>
<b>Please note:</b> All contact fields are optional and your prayer requests are kept strictly confidential.
</p>
</div>
<!--/ Show Prayer Request Form-->
<div id="prayer-form">
<form name="prayer-form" action="send-mail.php" method="POST">
<label for="field_name">Name:</label> <input type="text" id="field_name" name="sender_name" placeholder="First Name, Last Name">
<br>
<label for="field_email">Email:</label> <input type="text" id="field_email" name="sender_email" placeholder="[email protected]">
<br>
<label for="field_phone">Phone:</label> <input type="text" id="field_phone" name="sender_phone" placeholder="(444) 444-4444">
<br>
<label for="field_message">Prayer Request:</label>
<textarea id="field_message" name="sender_message" placeholder="How can we pray for you?"></textarea>
<br>
<?php
require_once('/bp/recaptchalib.php');
$publickey = "********************Po3UtfoqR1AzBk";
echo recaptcha_get_html($publickey);
?>
<br>
<input type="submit" name="send_message" value="Submit"> <input type="reset" value="Reset">
</form>
</div>
<div class="bottom-block"><img src="/bp/images/white-block.jpg"></img></div>
</body>
</html>
<?php include 'footer.php'; ?>
發送-Mail.php
<?php
require_once('/bp/recaptchalib.php');
$privatekey = "*******************yfYWTRW0hG7CrJ8hItb";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>
<?php
$mail_to = "[email protected]"; // specify your email here
// Assigning data from the $_POST array to variables
$name = $_POST['sender_name'];
$mail_from = $_POST['sender_email'];
$phone = $_POST['sender_phone'];
$web = $_POST['sender_web'];
$company = $_POST['sender_company'];
$addy = $_POST['sender_addy'];
$message = $_POST['sender_message'];
// Construct email subject
$subject = 'Email Web Prayer Request from ' . $name;
// Construct email body
$body_message = 'From: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Phone: ' . $phone . "\r\n";
$body_message .= 'Prayer Request: ' . $message;
// Construct email headers
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $mail_from . "\r\n";
$mail_sent = mail($mail_to, $subject, $body_message, $headers);
if ($mail_sent == true){ ?>
<script language="javascript" type="text/javascript">
alert('Your prayer request has been submitted - thank you.');
window.location = 'prayer-request.php';
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
alert('Message not sent. Please, notify the site administrator [email protected]');
window.location = 'prayer-request.php';
</script>
<?php
}
?>
您的郵件表單很容易被郵件頭注入。將參數檢查爲「mail」,因此它們只能包含有效值。 – 2013-03-16 16:31:37