I recently made a portfolio website and put it online on 000webhost.com. Today when I logged in, the account was suspended because someone sent more then 70 emails in a minute via my contact form – something that the webhosting does not allow.
I am looking for some way to stop this from hapening again. I used both php and javascript/jquery for form validation.
This is my curent php validation code.
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
$message = $_POST["message"];
$to = "fox.team001@gmail.com";
$subject = $firstName . " " . $lastName;
$headers = "From: " .$firstName . " " . $lastName . "\r\nReply-To:" . $email;
if(validateEmail($email)){
@mail($to , $subject , $message , $headers);
}
validate($firstName , $lastName , $email , $message);
function validate ($firstName , $lastName , $email , $message){
if(!empty($firstName) && !empty($lastName) && !empty($email) && !empty($message)){
if(validateEmail($email)){
header("refresh:5; url=http://www.foxteam.net");
}else{
header("refresh:0; url=http://www.foxteam.net/contact.php");
}
}else{
header("refresh:0; url=http://www.foxteam.net/contact.php");
}
}
function validateEmail($email) {
$pattern = "^[A-Za-z0-9_\-\.]+\@[A-Za-z0-9_\-]+\.[A-Za-z0-9]+$";
if(preg_match("/{$pattern}/", $email)) {
return true;
}else{
return false;
}
}
Can anyone tell me how can I stop spammers to send spam emails?
It’s very hard to stop spam coming through a contact form completely, however there are a number of methods you can use to reduce it, some of which include:
answer), if this field has anything in it, then don’t bother sending the email (but still tell the user that the email has been sent) – it is obviously spam as there is no other way the field could have been filled out.