reCAPTCHA和SMTP php脚本错误

时间:2014-01-30 21:43:49

标签: php recaptcha

这是我的代码,并希望工作:((哪里错了:???我尝试在任何模式下做代码工作,soryy为我的坏英语,请检查此代码并告诉我哪里有问题

<?
$account_id = secure($_SESSION['user']);
$query = mssql_query("Select * FROM MuOnline.dbo.MEMB_INFO where memb___id='$account_id'");
$row = mssql_fetch_array($query);
?>
<h1>Report Abuse</h1>

<?
include('includes/mail/google/SMTPconfig.php');
include('includes/mail/google/SMTPClass.php');


if(isset($_POST['submit'])){
require_once('security/recaptchalib.php');
$privatekey = "private_key";
  $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 {
    $to = "mail@yahoo.com"; // this is your Email address
    $from = $row['mail_addr']; // this is the sender's Email address
    $first_name = $row['memb___id'];
    $subject = "Report Abuse $first_name";
    $body = $_POST['message'];

$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
echo "<span class='succes'>Mail Sent. Thank you <b>" . $first_name . "</b>, we will contact you shortly.</span>";
}//end captcha
}
?>
<form action="" method="post">
<table>
<tr><td>
<b>Your Message:</b><br />please write with carefull.
</td>
<td>
<textarea rows="5" name="message" cols="30"></textarea></td>
</tr>
<?php
require_once('security/recaptchalib.php');
$publickey = "public"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
<tr>
<td colspan="2"><center>
<input type="submit" name="submit" value="Submit">
</center>
</td>
</tr>
</form>

我想在一个php文件中使用邮件脚本,并且此代码页显示如下:http://scr.hu/0fbv/rlufi

1 个答案:

答案 0 :(得分:0)

您要包括security/recaptchalib.php两次,但这不是问题。

但是,您需要指定$publickey$privatekey变量。现在,你只需将它们作为&#34; public&#34;和#34;私人,&#34;分别。您可以在此处获取reCAPTCHA API密钥:https://www.google.com/recaptcha/admin/create

您还应该使用<?php而不是<?

这里有一些修改后的代码可以让它更清晰:

<?php

include('includes/mail/google/SMTPconfig.php');
include('includes/mail/google/SMTPClass.php');
require_once('security/recaptchalib.php');

/****************** CHANGE THIS ***************/
$publickey = "public"; // you got this from the signup page
$privatekey = "private_key";

$account_id = secure($_SESSION['user']);
$query = mssql_query("Select * FROM MuOnline.dbo.MEMB_INFO where memb___id='$account_id'");
$row = mssql_fetch_array($query);

echo "<h1>Report Abuse</h1>";

if(isset($_POST['submit'])){
  $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 {
    $to = "mail@yahoo.com"; // this is your Email address
    $from = $row['mail_addr']; // this is the sender's Email address
    $first_name = $row['memb___id'];
    $subject = "Report Abuse $first_name";
    $body = $_POST['message'];

$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
echo "<span class='succes'>Mail Sent. Thank you <b>" . $first_name . "</b>, we will contact you shortly.</span>";
}//end captcha
}
?>
<form action="" method="post">
<table>
<tr><td>
<b>Your Message:</b><br />please write with carefull.
</td>
<td>
<textarea rows="5" name="message" cols="30"></textarea></td>
</tr>
<?php

echo recaptcha_get_html($publickey);
?>
<tr>
<td colspan="2"><center>
<input type="submit" name="submit" value="Submit">