Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    51
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Question How do I block a certain email from being entered in my forms?

    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:
    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?

  • #2
    New Coder
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    2
    Thanked 1 Time in 1 Post
    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

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    51
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Thanks, do you have a statement I can use?

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Just add an if-else statement. For example:

    PHP Code:
    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)


  • Users who have thanked binaryWeapon for this post:

    samsfriend (08-15-2008)

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    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)
    }

  • #6
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Wouldn't that be OR instead of AND?

    As in:
    PHP Code:
    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)


  • #7
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    PHP Code:
    $blocked = array(
        
    'spammer@spam.com',
        
    'spam@aol.com',
    );

    $email $_POST['emailAddress'];

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


  • #8
    Regular Coder
    Join Date
    Jun 2008
    Posts
    680
    Thanks
    114
    Thanked 2 Times in 2 Posts
    Shouldn't you worry more about the IP address as opposed to just the email address?

  • #9
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    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.

  • #10
    New Coder
    Join Date
    Aug 2008
    Posts
    51
    Thanks
    18
    Thanked 0 Times in 0 Posts
    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!

  • #11
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Yeah OR || would probably work better


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •