- Joined
- Aug 17, 2008
- Messages
- 4,883
- Points
- 860
I've started to get spam though my contact form, its only happened a few times, but I want to get it fixed before it becomes a huge problem.
Below is the form I have, which is on my contact page.
And below is the code I have in email.php
(Taken my email address out so I dont get even more spam ).
I was thinking of maybe adding something so you have to type the numbers that a image is showing. Or a quick sum or something.
Does anyone have any ideas on how to go around this? Tutorials or something.
Cheers.
Below is the form I have, which is on my contact page.
Code:
<form action="email.php" method="post">
<p>Name: <input type="text" name="name" size="30" maxlength="60" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" /></p>
<p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p>Comments: <textarea name="comments" rows="5" cols="30"><?php if (isset($_POST['comments'])) echo $_POST['comments']; ?></textarea></p>
<p><input type="submit" name="submit" value="Send!" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
And below is the code I have in email.php
Code:
<?php # Script 10.1 - email.php
// Check for form submission:
if (isset($_POST['submitted'])) {
// Minimal form validation:
if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['comments']) ) {
// Create the body:
$body = "Name: {$_POST['name']}\n\nComments: {$_POST['comments']}";
// Make it no longer than 70 characters long:
$body = wordwrap($body, 70);
// Send the email:
mail('[email protected]', 'Contact Form Submission', $body, "From: {$_POST['email']}");
// Print a message:
echo '<p><em>Thank you for contacting me. I will reply as soon as possible.</em></p>';
// Clear $_POST (so that the form's not sticky):
$_POST = array();
} else {
echo '<p style="font-weight: bold; color: #C00">Please fill out the form completely.</p>';
}
} // End of main isset() IF.
// Create the HTML form:
?>
(Taken my email address out so I dont get even more spam ).
I was thinking of maybe adding something so you have to type the numbers that a image is showing. Or a quick sum or something.
Does anyone have any ideas on how to go around this? Tutorials or something.
Cheers.