如果在联系表单中填写了隐藏字段,如何对phpMailer进行编码以防止发送电子邮件 [英] How to Code phpMailer to prevent sending email if hidden field is filled in contact form

查看:69
本文介绍了如果在联系表单中填写了隐藏字段,如何对phpMailer进行编码以防止发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢phpMailer,但是当我使用以前的邮件程序时,它具有反垃圾邮件代码.

I like phpMailer but when I used a previous mailer it had an anti spam code.

您在联系表单中添加了一个隐藏字段,并且对mail.php脚本进行了编码,如果填写了该隐藏字段(即,只有垃圾邮件机器人会这样做),邮件将不会发送

You added a hidden field in the contact form and the mail.php script was coded that if the hidden field was filled in (i.e. only a spam robot would do that) the mail wouldnt send

如何将其添加到此脚本中?

How would I add that to this script?

这是我的mail.php代码,如下所示

This is my mail.php code as follows

<?php

// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$name = $_REQUEST['name'] ;
$phone = $_REQUEST['phone'] ;
$address = $_REQUEST['address'] ;
$postcode = $_REQUEST['postcode'] ;
$service = $_REQUEST['service'] ;
$height = $_REQUEST['height'] ;
$how = $_REQUEST['how'] ;
$website = $_REQUEST['website'] ;
$mail_intro ="The following enquiry came from your web site:";
// When we unzipped PHPMailer, it unzipped to
// public_html/PHPMailer_5.2.0
require("class.phpmailer.php");
$mail = new PHPMailer();
// set mailer to use SMTP
$mail->IsSMTP();
// As this email.php script lives on the same server as our email server
// we are setting the HOST to localhost
$mail->Host = "localhost";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "franchise@website.co.uk";  // SMTP username
$mail->Password = "passowrd"; // SMTP password
$mail->From = "noreply@website.co.uk";
$mail->FromName = "B";
$mail->AddReplyTo($email,$name);
$mail->AddAddress("franchise@website.co.uk", "B");
$mail->AddBCC("joseph@website.co.uk", "Joseph");
$response="$mail_intro\n<br />Name: $name\n<br />Email: $email\n<br />Phone: $phone\n<br />Address: $address\n<br /> Comments:\n$message\n<br /> Website: $website\n";

// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);

$mail->Subject = "Enquiry";

// $message is the user's message they typed in
// on our contact us page. We set this variable at
// the top of this page with:
// $message = $_REQUEST['message'] ;
$mail->Body = $response;
$mail->AltBody = $message;
//Autoresponder
$mailto="$email";
$subject="Franchisee Enquiry";

$body.="Thanks for your enquiry, the message below has been sent. \n";
$body.="If due to an unknown technical error you do not receive a response within 4 hours please phone  \n";
$body.="or email us directly at info@website.co.uk where we will be only too happy to help.\n";
$body.="$mail_intro\n";
$body.="Name: $name\n";
$body.="Email: $email\n";
$body.="Phone: $phone\n";
$body.="Postcode: $postcode\n";
$body.="Service Required: $service\n";
$body.="How found: $how\n";
$body.="Comments:\n$message\n";
mail($mailto,$subject,$body,"From: noreply@website.co.uk\n");
if(!$mail->Send())
{
   header("Location: http://website.co.uk/error.php");
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

header("Location: http://website.co.uk/thankyou.php");

?>

推荐答案

在您的HTML中,添加:

In your HTML, add:

<input type="text" name="fooBarBaz" style="display: none">

在您的PHP中:

if ( !empty($_REQUEST['fooBarBaz']) )
{
    // hidden field was filled out, do something about it
}
else
{
    $email = $_REQUEST['email'];
    ...
}

这篇关于如果在联系表单中填写了隐藏字段,如何对phpMailer进行编码以防止发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆