0

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


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


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

这是我的mail.php代码如下


<?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");

?>
4

1 回答 1

2

在您的 HTML 中,添加:

<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'];
    ...
}
于 2013-09-18T18:53:17.490 回答