Jump to content

PHP Forms - help with form spam please!!


john8m

Recommended Posts

Hi all,

 

I need help with my php forms. I read an article that you can prevent form spam by using a hidden field, and requiring it to be blank for the form to be processed. I have no problems with setting the required html / css up, but have no idea where to start with the php code required to stop the form from being sent if left blank. I have very limited knowledge of php, please bare this in mind.

 

Anyone point me in the right direction or explain the code to me please?

 

I've tried a search on the forum but couldn't find anything, and sites that have mentioned the method never explain what you need to do with the php!

 

Thanks in advance...!

Link to comment
https://forums.phpfreaks.com/topic/91069-php-forms-help-with-form-spam-please/
Share on other sites

Hi, I built the site from scratch, its a very simple site - just static html. The only php is for the form.

 

The form just sends an enquiry to an email address.

 

I'm getting lots of spam everyday, and it's all just random text and lots of links to viagra medication etc. It must be automatically generated, it all looks very similar.

 

HERES the php - I adapted this from something I found on the web ages ago.

 

<?php

 

// Handle POST method.

if ($_POST)

{

$name = $_POST['name'];

$email = $_POST['email'];

$phone = $_POST['phone'];

$referrer = $_POST['referrer'];

$messagebody = $_POST['messagebody'];

 

// Compose simple text message:

$message = "

 

------------------------------------------------------------

CONTACT FORM

------------------------------------------------------------

Name: $name

Email: $email

Phone: $phone

Referrer: $referrer

------------------------------------------------------------

\nMessage: $messagebody

------------------------------------------------------------

";

 

 

// Send message to [email protected]

mail("[email protected]", "CONTACT FORM - $name - $email", $message);

 

// Thank the generous user

header("Location:http://www.example.com/thanks.php");

 

 

 

}

else

{

?>

 

 

 

Here is what I would do, in your Form area, have a sentence that says something like

 

"Hi, please submit the form below for blah blah..etc"

 

Then, create a new input field and have a question that says

 

"What is the third word in the above sentence?"

 

If they don't answer "submit" then don't accept the form.

 

And the good thing is, you can change this validation at will.

Thanks, but I really want to use the method of a hidden field that should be left blank for usability reasons.

 

What I really want to know is, how do you stop a form from being sent - what is the php code?

 

For example could I use an "if" statement that abandons the process if the "hidden" field is filled in by a spam bot?

 

What would the php be to do this?

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.