Search code examples
emailblockspam-prevention

Exclude specific email address from form submissions


I am totally new to PHP and I am just trying to block spam in my forms. I have figured out how to do a honeypot (url field) with the following code that blocks 90% of the spam - but this one irritating emailer gets through (let's call them [email protected]). I would like to write one line of code in my form that just says if the email field is filled out with the text '[email protected]', then don't pass the form through. Is there anyone who can help me do this?

// if the url field is empty
// if(isset($_POST['url']) && $_POST['url'] == ''){

// then send the form to your email
// mail( '[email protected]', 'Contact Form', print_r($_POST,true) );
// }

// otherwise, let the spammer think that they got their message through

Solution

  • Use this code

    if(isset($_POST['url']) && $_POST['url'] == '') {
        if ($_POST['email'] != '[email protected]') {
            // then send the form to your email
             mail( '[email protected]', 'Contact Form', print_r($_POST,true) );
        }
    }