0

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


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?

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 = "[email protected]";  // SMTP username
$mail->Password = "passowrd"; // SMTP password
$mail->From = "[email protected]";
$mail->FromName = "B";
$mail->AddReplyTo($email,$name);
$mail->AddAddress("[email protected]", "B");
$mail->AddBCC("[email protected]", "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 [email protected] 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: [email protected]\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");

?>
5

1 Answer 1

2

In your HTML, add:

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

And in your PHP:

if ( !empty($_REQUEST['fooBarBaz']) )
{
    // hidden field was filled out, do something about it
}
else
{
    $email = $_REQUEST['email'];
    ...
}
4
  • Thankyou - sorry for being a novice but how do incorporate this in my code? Sep 18, 2013 at 18:57
  • That is how, my example includes the first line of your code ($email = $_REQUEST['email'];).
    – Mark
    Sep 18, 2013 at 19:00
  • what are the ... for - do i have to put something in this place? Sep 18, 2013 at 19:01
  • Yes, the rest of your code, seeing as I only included the first line, while you need to copy everything else.
    – Mark
    Sep 18, 2013 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.