Page 1 of 2
Form code with honey pot not working?
Posted: Wed Nov 26, 2008 5:20 pm
by weavers
Hi
I have the following form code, I have a honey pot form field which is hidden with css called 'Email' The problem is the email isn't being sent, can anyone point me in the right direction.
I'm feeling out of my depth!
Code: Select all
<?
$mail_content =
"Dear Joe Bloggs\n\n".
"Please could you provide me with a quote, my details are as follows:\n\n".
"Title: ".$_POST['Contact_Title']."\n".
"Contact Name: ".$_POST['Contact_Name']."\n".
"Company Name: ".$_POST['Company_Name']."\n".
"Postcode: ".$_POST['Postcode']."\n\n".
"E-mail: ".$_POST['Email2']."\n".
"Telephone: ".$_POST['Contact_Telephone']."\n".
"How did you find us: ".$_POST['find_us']."\n\n".
"Im Interested: ".$_POST['Interested']."\n\n".
"Message body: ".$_POST['Message_Body']."\n";
echo nl2br($mail_content);
// Check the spam trap to see if it has data in it. If it does, don't bother mailing the form.
if (!isset($_POST['Email'])) {
mail("my@email.com", $Interested, $mail_content);
}
?>
Thanks for any help.
Re: Form code with honey pot not working?
Posted: Wed Nov 26, 2008 7:57 pm
by pinoypride
I don't know if you've just forgot to include this ();
Basically, I added this:
$mail_content = ( "Text1" . "Text2");
=======================
Here's the new code:
Code: Select all
<?php
$mail_content = (
"Dear Joe Bloggs\n\n".
"Please could you provide me with a quote, my details are as follows:\n\n".
"Title: ".$_POST['Contact_Title']."\n".
"Contact Name: ".$_POST['Contact_Name']."\n".
"Company Name: ".$_POST['Company_Name']."\n".
"Postcode: ".$_POST['Postcode']."\n\n".
"E-mail: ".$_POST['Email2']."\n".
"Telephone: ".$_POST['Contact_Telephone']."\n".
"How did you find us: ".$_POST['find_us']."\n\n".
"Im Interested: ".$_POST['Interested']."\n\n".
"Message body: ".$_POST['Message_Body']."\n"
);
echo nl2br($mail_content);
// Check the spam trap to see if it has data in it. If it does, don't bother mailing the form.
if(!isset($_POST['Email']))
{
mail("my@email.com", $Interested, $mail_content);
}
?>
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 4:51 am
by weavers
Hi pinoypride
Thanks for the reply, I tried your suggestion but it broke the code and didn't display the confirmation page let alone send the email.
The form works fine if I remove the honey pot section:
if(!isset($_POST['Email']))
{
mail("
my@email.com", $Interested, $mail_content); - (Not removing this line of course)
}
So i'm a bit stuck!
Many Thanks
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 1:21 pm
by pinoypride
Sorry, I misunderstood your post.
Code: Select all
// Check the spam trap to see if it has data in it. If it does, don't bother mailing the form.
- Were you trying not to send email if $_POST['email'] is not empty?
Try this:
if(empty($_POST['email']))
or if you are validating that variable that shouldn't be empty:
if(!empty($_POST['email']))
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 1:37 pm
by mmj
I have the following form code, I have a honey pot form field which is hidden with css called 'Email' The problem is the email isn't being sent, can anyone point me in the right direction.
http://php.net/isset
Because it will always be sent, even if the user (or bot) doesn't fill it due to how isset works (see url above).
replace
with
.
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 2:17 pm
by John Cartwright
This is
NOT recommended because it will throw a notice if the variable does not exist. Instead as already suggested, use empty() instead of isset()
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 2:42 pm
by mmj
Jcart wrote:
This is
NOT recommended because it will throw a notice if the variable does not exist. Instead as already suggested, use empty() instead of isset()
So just use @ if you are worried about E_NOTICE, will give you the same exact thing as empty.
I'm pretty sure it would be better performance wise too.
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 2:43 pm
by John Cartwright
mmj wrote:Jcart wrote:
This is
NOT recommended because it will throw a notice if the variable does not exist. Instead as already suggested, use empty() instead of isset()
So just use @ if you are worried about E_NOTICE, will give you the same exact thing as empty.
Eeek! The usage of @ should be avoided unless completely necesary. There is a reason it is throwing a notice, because you are doing something wrong!
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 2:46 pm
by mmj
Jcart wrote:Eeek! The usage of @ should be avoided unless completely unnecesary. There is a reason it is throwing a notice, because you are doing something wrong!
Haha.
My views on this matter are different however, so we will respectfully disagree.

Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 2:48 pm
by John Cartwright
P.S. the @ is an "Error control operator" -- not the supress errors because I'm lazy operator
It is not a matter of opinion, it is a matter of what is right and wrong. You are supressing an error because you are using a variable that does not exist. In fact, it is proper programming to ensure a variable exists before using it.
And if you disagree with that.. well... lets just leave it there
P.S., check your PHP error logs. They are probably massive if this is how you feel.
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 3:00 pm
by mmj
I agree but empty is just as much as surpressor as @ and has no "semantics".
If you were doing something like (isset($_POST['email']) && $_POST['email']) then that would make much more sense and also no errors would be shown.
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 3:05 pm
by John Cartwright
mmj wrote:I agree but empty is just as much as surpressor as @ and has no "semantics".
If you were doing something like (isset($_POST['email']) && $_POST['email']) then that would make much more sense and also no errors would be shown.
Actually empty() provides the added benefit of checking the variable has a (positive) value, so that is incorrect.
Code: Select all
isset($_POST['email']) && $_POST['email']
is the exact same thing as writting
So if I understand you correct, you are saying ignore the usage of isset() and empty() in favor of supressing errors?
Re: Form code with honey pot not working?
Posted: Thu Nov 27, 2008 3:11 pm
by Eran
empty() and isset() are not suppressors - they give you a chance to perform error handling. In general, it is bad practice to suppress errors.
Re: Form code with honey pot not working?
Posted: Fri Nov 28, 2008 7:30 am
by mmj
Jcart wrote:Actually empty() provides the added benefit of checking the variable has a (positive) value, so that is incorrect.
...
pytrin wrote:empty() and isset() are not suppressors - they give you a chance to perform error handling. In general, it is bad practice to suppress errors.
I didn't say isset is a suppressor.
empty however, is a suppressor.
http://php.net wrote: empty() is the opposite of (boolean) var,
except that no warning is generated when the variable is not set.
so
equals
just E_NOTICE errors are suppressed.
As said by the php manual!
Re: Form code with honey pot not working?
Posted: Fri Nov 28, 2008 11:42 am
by John Cartwright
my goodness.
empty() does not supress the error, it will gracefully checks for the existance of the variable before using it. I'll have to look up the source code if this continues on, because I'll be damned if the PHP core generates internal errors in the source.
However, calling empty() an error supressor simply isn't right. It's purpose is not to supress errors.