I am trying to set up a mail form that can not be spammed through and I have this script that attempts to do this in two ways.
1) it checks the url of the page and the url of the refering page and makes sure they are the same or it does not process email form
2) it is supposed to strip the slashes from the data inputed in the email forms
number 1 works great, but stripping the slashes from the inputed text is not working for some reason. Here is the script for the email form so you can take a look.
<?php
$your_email = "";
$subject = "Message via your contact form";
$empty_fields_message = "<p>Please go back and complete all the fields that are required in the form.</p>";
$thankyou_message = "<p>Thankyou. Your message has been sent.</p>";
$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);
if (!isset($_POST['txtName'])) {
?>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p><label for="txtName">Name:</label><br />
<input type="text" title="Enter your name" name="txtName" /></p>
<p><label for="txtEmail">Email:</label><br />
<input type="text" title="Enter your email address" name="txtEmail" /></p>
<p><label for="txtMessage">Your message:</label><br />
<textarea title="Enter your message" name="txtMessage"></textarea></p>
<p><label title="Send your message">
<input type="submit" value="Send" /></label></p>
</form>
<?php
}
elseif (empty($name) || empty($email) || empty($message)) {
echo $empty_fields_message;
}
else {
// Check the refering URL
$referer = $_SERVER['HTTP_REFERER'];
// Get the URL of this page
$this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
// If the referring URL and the URL of this page don't match then
// display a message and don't send the email.
if ($referer != $this_url) {
echo "You do not have permission to use this script from another URL.";
exit;
}
// The URLs matched so send the email
mail($your_email, $subject, $message, "From: $name <$email>");
// Display the thankyou message
echo $thankyou_message;
}
?>
Not sure what is wrong I guess it is a little over my head.
Thanks for the help.