...

View Full Version : How do I block a certain email from being entered in my forms?



samsfriend
08-10-2008, 04:37 AM
I have a simple PHP contact form. But I have email spammer ex that keeps filling out my form. How do I add a block so that email cannot even be sent from the spammer ex?
Heres my code:

<?php


// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "samsy@yahoo.com";
$Subject = "Our Form";
$FirstName = Trim(stripslashes($_POST['FirstName']));
$LastName = Trim(stripslashes($_POST['LastName']));
$Phone = Trim(stripslashes($_POST['Phone']));
$Reason = Trim(stripslashes($_POST['Reason']));
$IP=$_SERVER['REMOTE_ADDR'];

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=oops.html\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "FirstName: ";
$Body .= $FirstName;
$Body .= "\n";
$Body .= "LastName: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Reason: ";
$Body .= $Reason;
$Body .= "\n";
$Body .= $IP;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=oops.html\">";
}
?>

I know that I could do 100 things, but I just want to block person@thisemail.com from addeding there info. Oh and maybe there is a way to redirect that person to another page that says, Thanks for trying to spam us or something like that?

infinivert
08-10-2008, 04:53 AM
A simple if statement should do it, but it might be a good idea to put your e-mail address into a database table or xml file so that if the guy goes and gets a different e-mail address, all you have to do is add it to the list rather than messing with your hard code.

--Josh

samsfriend
08-10-2008, 02:32 PM
Thanks, do you have a statement I can use?

binaryWeapon
08-10-2008, 02:59 PM
Just add an if-else statement. For example:



if($email=="spammers.email@spammer.com")
{
echo "Sorry, you have been blocked from this service";
}
else{
// Execute the rest of your normal code (send the email, etc)
}

masterofollies
08-10-2008, 03:20 PM
As Binary said, another way you can do for multiple emails.

if(($email=="spammers@spammer.com") && $email == "bob@aol.com" && $email == "Ilovespam@spam.com")
{
echo "Sorry, you have been blocked from this service";
}
else{
// Execute the rest of your normal code (send the email, etc)
}

binaryWeapon
08-10-2008, 03:45 PM
Wouldn't that be OR instead of AND?

As in:

if($email=="spammers@spammer.com" || $email == "bob@aol.com" || $email == "Ilovespam@spam.com")
{
echo "Sorry, you have been blocked from this service";
}
else{
// Execute the rest of your normal code (send the email, etc)
}

kbluhm
08-10-2008, 04:55 PM
$blocked = array(
'spammer@spam.com',
'spam@aol.com',
);

$email = $_POST['emailAddress'];

if ( in_array( $email, $blocked ) )
{
echo 'Your email address has been blocked';
}

CoolAsCarlito
08-10-2008, 05:46 PM
Shouldn't you worry more about the IP address as opposed to just the email address?

binaryWeapon
08-10-2008, 08:40 PM
Neither one is 100&#37; efficient. There are mail systems like mailinator.com that allow you to just make an email on the fly without even signing up for anything, therefore allowing an infinite amount of emails. This cannot even be avoided by blocking email addresses from mailinator.com because there are a large number of alternate domains. Even if you did manage to block every single mailinator clone, people can just go create an extra email account. Email is free nowadays, and is rather easy to set up.

However, I also understand that many people have dynamic IPs, making it impossible to block them by IP. In addition, blocking IPs leads to problems with shared computers, like at libraries, etc.

samsfriend
08-12-2008, 02:02 PM
Just wanted to say thank you all. I got it working! Hopefully this will stop it, but we will see. Just wanted to also say, I can't block the ip because they use DSL and they have the same ip's as users I want on our site. If nothing else hopefully this will bug them enough that they give up.
So thanks agian!

masterofollies
08-12-2008, 02:24 PM
Yeah OR || would probably work better :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum