Log in

View Full Version : PHP form need required fields and anti spam security



shush1
03-11-2008, 10:19 AM
Hi I have created a form that I want results sent to my email but i want it to have required fields and make the form secure from spam. My php looks like this: Can someone help me make the fields required and secure from spam please?

Thanx

codeexploiter
03-11-2008, 11:03 AM
You can validate your form fields using JavaScript and PHP (the PHP part is optional) before sending the mail.

The following page will give you a step by step explanation about various mail sending methods in PHP using the normal mode:

http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php

PEAR PHP extension supports a mail class which contains various utilities and you can make use of that if you need that:

http://www.hudzilla.org/phpbook/read.php/15_5_2

For me when I've used the mail function of PHP sometimes it acted as spams and when I used the PEAR it worked for me.

Master_script_maker
03-11-2008, 08:36 PM
i think you mean the other way around. the javascript is optional. php is mandatory. people could bypass the javascript by disabling it.

alexjewell
03-14-2008, 02:26 PM
Master Script Maker is right: if validation is necessary, use javascript to make it easier but do not rely on that javascript.

boogyman
03-14-2008, 03:15 PM
$sendit = mail("my@email.co.uk", "Website contact form", $result, $headers) or die("Something went wrong");

echo "<meta http-equiv='refresh' content='0; url=thank.htm'>";
die;

?>


get rid of the html redirect, instead use


if(mail("my@email.co.uk", "Website contact form", $result, $headers))
{
// sends the user to the good page
header('thank.htm');
}
else
{
// kills the processing and prints an error
die('Could not send email');
}