Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > RocketCake
Spam via the contact form

gethightech
Registered User
Quote
2017-06-27 00:08:42

I used the java and example that was given and have a working contact form on my site. Only issue is I am getting 3-5 spam email via the form daily. Any suggestions on how to fix this or add a captcha of some sort. Anything to slow down the spam bots?

Thanks,
Rob


niko
Moderator
Quote
2017-06-27 07:56:17

You could probably add a nother field to the form. Name that field "verification", and tell your users to type a specific word into it. Let it be "foobar" in this example. So in your code, you now only need to check for this field to be foobar:

$text = "";
foreach($_POST as $name => $value)
{
$text .= "$name : $value\n";
}

if ($text != "" && $_POST["verification"] == "foobar")
{
echo 'Thanks for contacting us.';
mail("youremail@example.com", "Contact form request", $text);
}
else
if ($text != "")
echo 'Please enter the verification field correctly.';



gethightech
Registered User
Quote
2017-06-28 16:35:20

Hi Niko,

So is that the only code I need and just replace the current one? Sorry I only got the form working by following the step by step on the RC area.

R.


niko
Moderator
Quote
2017-06-29 04:10:47

Yes, that's all the code. But don't forget to add a third field to your form (like you added a filed for the text and for the email address) and set its name in the property window to "verification"


gethightech
Registered User
Quote
2017-06-30 02:49:11

In the code where do I enter the word "foobar" as the word it will check?

I made the text edit field and gave it a name of verification already. Not working when I upload since I think I am not clear where to put 'foobar" in the code.


niko
Moderator
Quote
2017-06-30 08:21:02

Oh, I had mistyped the code above, now it is corrected (I had written "verification" instead of "foobar") now it should be more clear :)


gethightech
Registered User
Quote
2017-07-03 20:41:00

when i upload the page with that code I get an error trying to goto it. I had to switch it back to the old page so it works.

HTTP 500 error
That’s odd... the website can’t display this page
The site may be under maintenance or could have a programming error.
Try this
Go back to the last page
Try contacting the website’s owner


niko
Moderator
Quote
2017-07-04 08:16:37

Try pasting without those tabs. You probably have a syntax error in your php. You just don't see them because your web server is configurated not to show them. It is probably easier to enable them and see what the exact error is (so I'm just guessing). Try with this:

$text = "";
foreach($_POST as $name => $value)
{
$text .= "$name : $value\n";
}

if ($text != "" && $_POST["verification"] == "foobar")
{
echo 'Thanks for contacting us.';
mail("youremail@example.com", "Contact form request", $text);
}
else
if ($text != "")
echo 'Please enter the verification field correctly.';



gethightech
Registered User
Quote
2017-07-05 22:08:10

So from what I can tell using a PHP tester online. The error seems to be in the following code:

if ($text != "" && _$POST["verification"] != "foobar")

The online tester says the following:

FATAL ERROR syntax error, unexpected '$POST' (T_VARIABLE)


niko
Moderator
Quote
2017-07-06 19:20:21

Ah, you are right, sorry. There was a typo. I fixed that code, now it works.


gethightech
Registered User
Quote
2017-07-10 23:38:51

I get the following message "Please enter the verification field correctly." before I even enter anything into the fields

Here take a look:

http://axmicro.com/contact.php


niko
Moderator
Quote
2017-07-11 10:12:12

I assumed you wanted this on a target page only. I've updated the code to make it work both on the same as on the target page.


gethightech
Registered User
Quote
2017-07-11 19:27:23

Now the error is gone but we are now back to being able to send a message without having to enter the word foobar. I was able to send a message without the verification entered and it sent???


niko
Moderator
Quote
2017-07-13 07:07:15

You are right. Sorry. Updated the code again. Next time I'll check this before posting.


gethightech
Registered User
Quote
2017-07-13 18:42:31

Works perfect. Thank you so much.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact