How can I make a web form, using phpmailer, adding captcha and hidden empty field? I need a tutorial.

I have a simple web form which is sending me spam emails. I suppose there should be robots, and I want to add an empty field just to avoid them, as someone suggested, and a captcha security code. I'm using phpmailer, but I know only html and a little of php. I need a tutorial please.
JuancabritoAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
Juancabrito: I can give you the code I use for this purpose. You will need to modify both the form and action scripts.  I will post the captcha generator, then the form script changes and finally  the action script changes.  I cannot tell you where to make these changes - you will need to open up the code of PHPMailer and decide that for yourself.

Install this and name it captcha_number.php
<?php // captcha_number.php GENERATE A PICTURE OF A NUMBER
 $data	= base64_decode($_GET['dt']);
 $im	= imagecreate(46,13);
 $bg	= imagecolorallocate($im, 255,255,255);
 $gray	= imagecolorallocate($im, 188,188,188);
 $text	= imagecolorallocate($im, 178,34,34);  // firebrick
 imagestring($im,5,4,0,$data,$text);
 imageline($im,4,12,38,0,$gray);
 imagepng($im);
 imagedestroy($im);
?>

Open in new window

0
 
Ray PaseurCommented:
Rather than try to learn enough PHP and HTML to repair phpmailer, you might want to look for an alternative application.  Have a look at this...

http://www.swiftmailer.org/

HTH, ~Ray
0
 
JuancabritoAuthor Commented:
Thank you Ray, I can try it out, but where's how I can include the captcha and the hidden field using swift mailer?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Ray PaseurCommented:
You may not need to do anything at all... An easy way to find out about this issue is to post a question in the developers forum on their web site.  
0
 
JuancabritoAuthor Commented:
That's nice Ray, but I'm paying for this service, going to another forum to wait for the answer doesn't seem fair to me.
0
 
Ray PaseurConnect With a Mentor Commented:
Add this sequence to your form script
Human beings only!  Please enter this number:
<img src=captcha_number.php?dt=<?php $x = mt_rand(1000,10000); echo base64_encode($x);?> />
<input type=hidden name='_newMd5' value =<?=md5($x)?> />
<input name="_newCode" type="text" maxlength="64" size="6" autocomplete="off" />

Open in new window

0
 
Ray PaseurConnect With a Mentor Commented:
Add this sequence to your action script
// AVOID INVALID SECURITY CODES
$newCode	= $_POST["_newCode"];
$newMd5		= $_POST["_newMd5"];
$newCode	= md5($newCode);
if ($newCode != $newMd5) {
	die("Captcha Error");
}

Open in new window

0
 
JuancabritoAuthor Commented:
Thank you very much Ray! I'll try it.
0
 
Ray PaseurCommented:
OK, good luck!
0
 
JuancabritoAuthor Commented:
Somehow every captcha solution available it works in my local server (XAMPP) but when I publish the form is sent anyway, even leaving the captcha code field empty.

Please help.
0
 
Ray PaseurCommented:
Please post the output you got from running my example.  I'll try to help. ~Ray
0
 
JuancabritoAuthor Commented:
This is happening with iCaptcha, reCAPTCHA, and others... and what I get is the "...your message was succesfully sent..." kind of message or page, and the email arrives.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.