Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Blocking free email accounts for online form

  • This topic is empty.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #37010
    kblake
    Participant

    I have an online form that allows a user to enter the email address they wish to send a message to and I’d like to block certain email addresses, like: gmail, hotmail, yahoo, etc from using the form. The site is in WP and I am using the plugin Contact Form 7 which doesn’t have the option to block email addresses and I have not found anything on WP’s forum as a solution. So I thought adding some php would resolve the issuse, however I don’t even know where to start. Any ideas would be great. Thanks.

    #98327
    ccc630
    Member

    If I can ask, what is the purpose of blocking those email hosts? You’ve listed three very popular domains which could lead to excluding a very large number of potential users. There may be an entirely legitimate reason to do so; I’m just curious.

    #98391
    kblake
    Participant

    I completley agree. The reason is my client has a site that allows kids to report bulling to a teacher and what is happening is students are sending messages to their friends. Since students use free email services my client would just like them blocked.

    #98400
    ccc630
    Member

    Gotcha; makes perfect sense. I’m assuming, then, that students would send the messages using a school-based email address ([email protected] or somesuch). I’m definitely not a wizard when it comes to regular expressions, but I found this thread:

    http://www.phpfreaks.com/forums/index.php?topic=137584

    which seems to be along the lines of what you’re looking for. The final script in that thread excludes a certain domain, but if all the legitimate messages would come from one domain, you could also modify it to only accept that one domain.

    Hope it helps. :)

    Chris

    #98513
    kblake
    Participant

    Thanks for the help and suggestions. Since this is a public site and there are many schools with their own domain, I am thinking just adding a few common email domains would make the most sense.

    I think I’m getting closer to resolving this. I added “if(strpos(strtolower…” (see code below) but I get the error “Parse error: syntax error, unexpected” when using this code. Any ideas on why? Or what I am missing?

    
    function wpcf7_text_validation_filter( $result, $tag ) {
    $type = $tag;
    $name = $tag;

    $_POST[$name] = trim( strtr( (string) $_POST[$name], "n", " " ) );
    if ( 'text*' == $type ) {
    if ( '' == $_POST[$name] ) {
    $result = false;
    $result[$name] = wpcf7_get_message( 'invalid_required' );
    }
    }

    if ( 'email' == $type || 'email*' == $type ) {
    if ( 'email*' == $type && '' == $_POST[$name] ) {
    $result = false;
    $result[$name] = wpcf7_get_message( 'invalid_required' );
    }

    if(strpos(strtolower( '' != $_POST[$name] && ! is_email( $_POST[$name] ),'[email protected]') ){
    $result = false;
    $result[$name] = wpcf7_get_message( 'invalid_email' );
    }
    }elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] ) ) {
    $result = false;
    $result[$name] = wpcf7_get_message( 'invalid_email' );
    }
    }
    return $result;
    }
    ?>
    #98543
    kblake
    Participant

    This is a public site and not specific to any one school. Anybody can use the site. To collect and manage every teacher’s email address from every school would be very cumbersome. If there is a way to block gmail, yahoo and hotmail email accounts that would be greatly helpful. Here is the link to the site in case anyone wants to check it out. http://bongokidz.com/report-bullying/

    Thanks!

    #98712
    ccc630
    Member

    This almost seems too easy, but could you adapt the code shown here?

    #99081
    kblake
    Participant

    I attempted to do something like this but it was rather advanced for my php skills. However, on WP’s forum I found a member who was extremely helpful and he provided the coded which was one of the methods I was attempting to use. Here is the link for those who may need it.

    Please note that this is for the Contact Form 7 plugin in WP and you’ll need to modify the text.php file under the Validation filter comment (line 113) in the modules folder.

    Thank you ccc630 for all your suggestions, they were very helpful and I learned a little more about php.

    #99118
    ccc630
    Member

    Glad you were able to get it running — I was a teacher for quite a few years, so I know first-hand how important a service like this is (sadly enough).

    #186260
    ggsmartboy
    Participant

    I’m very new to php and wordpress. I’m stuck with same problem. I need to filter free domains in only one contact form. @kbespinoza Can you say me step by step how you solve this problem ASAP.

    #186302
    __
    Participant

    @ggsmartboy, you do realize that this discussion has been dead for two and a half years? That the OP hasn’t been active on the forums for almost as long?

    These facts notwithstanding, you should start a new discussion for your question, rather than sidetracking someone else’s. Be sure to explain what you have already tried, and what problems you encountered, and include any relevant code.

    If, on the other hand, you are simply looking for someone to do the work for you (or give you “step by step instructions,” which is effectively the same thing), then you should consider hiring someone. People here will be very happy to help you learn and solve your problems, but it’s not a “do this for me” kind of community.

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘Back End’ is closed to new topics and replies.