所以我有一个自定义的PHP接触形式阻止垃圾邮件问题将被发送。我已经加入了谷歌验证码,也增加了一个功能,以检查是否隐藏字段已被填充,那么请不要发送消息。但我的客户仍在接受垃圾邮件。客户端也最近从HubSpot迁移代码,并想知道是否有可能是建于我缺少的部件东西。我是新的PHP所以请原谅所有新秀的错误:)。在此先感谢您的帮助!
HTML表格:
<div class="contact-form">
<form id="contact-form" method="post" action="contact-form-handler.php">
<input name="companyname" type="text" id="companyName" placeholder=" Company Name" required>
<input name="name" type="text" id="contactName" placeholder=" Contact Person" required>
<input name="email" type="email" id="Email" placeholder=" Your Email" required>
<p class="antispam">Leave this empty: <input type="text" name="url" /></p>
<input type="tel" id="Phone" name="Phone" placeholder=" Phone Number" required>
<textarea name="message" class='form-control' placeholder=" Write your message here..." style="white-space:pre-wrap; height:200px;width:500px;" row="4" required></textarea>
<div class="g-recaptcha" data-sitekey="6LcqLWkUA2AAADEMnsD4sZEj4BqmqGhx8CN5Hhqf" data-callback="recaptcha_callback"></div>
<input type="submit" id="submit_btn" name="submit_form" value="SEND MESSAGE" onclick="myFunction()" disabled>
</form>
</div>
PHP处理程序
if (isset($_POST['submit_form'])) {
$name = $_POST['name'];
$secretKey = "6LcqLWkUAAAAAOG_Z9lpScLz0nftfFoYgpENfwDp";
$responseKey = $_POST['g-recaptcha-response'];
$userIP = $_SERVER['REMOTE_ADDR'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
$response = file_get_contents($url);
$response = json_decode($response);
if ($response->success)
echo "Verification success. Your name is $name";
else
echo "Verification Failed";
}
$public_key = "6LcpmGgUAAAAAI6O2SQv1TdYu9z9yzmXclU2-rzu";
$private_key = "6LclmGgUAA2AALd9pZTaOzOV4tThdZNLeJ56WNno";
$reCaptchaUrl = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
$companyname = $_POST['companyname'];
$name = $_POST['name'];
$url = $_POST['url'];
$email = $_POST['email'];
$phone = $_POST['Phone'];
$message = $_POST['message'];
/* Check if the form has been submitted */
if(array_key_exists('submit_form',$_POST))
{
/* The response given by the form being submitted */
$response_key = $_POST['g-recaptcha-response'];
/* Send the data to the API for a response */
$response = file_get_contents($url.'?secret='.$private_key.'&response='.$response_key.'&remoteip='.$_SERVER['REMOTE_ADDR']);
/* json decode the response to an object */
$response = json_decode($response);
/* if success */
if($response->success == 1)
{
echo "You passed validation!";
}
else
{
echo "You are a robot and we don't like robots.";
}
// if the url field is empty
if(isset($_POST['url']) && $_POST['url'] == ''){
// then send the form to your email
mail( '[email protected]', '[email protected]', 'Contact Form', print_r($_POST,true) );
}
// otherwise, let the spammer think that they got their message through
}
埃姆,一个简单的检查:你有以下内容的一行:
echo "You are a robot and we don't like robots.";
......这行之后,你发送的邮件,无论验证码检查。
如果验证码检查失败,应立即通过类似exit
或die
停止脚本。这可能是第一步 - 或许,你应该多增加一些记录到你的代码调试这进一步,如果还有未来的垃圾邮件通过给客户。