• Resolved jrmoore1953

    (@jrmoore1953)


    I have a contact form that occasionally receives profane messages. The wanker is using a valid email address, so I would like to block him from sending messages to us. The messages are sent to a forwarding email alias, and then on to a dozen souls. It would be nice to blacklist this guy at the input form so that the email never goes out, and he is not notified of the blocking.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Hello @jrmoore1953,

    Thanks for contacting us!

    To do what you mentioned we need some custom PHP code, which I’ve included here:

    function wpf_dev_blacklist_domains( $field_id, $field_submit, $form_data ) {
     $blacklist = array( '[email protected]' );
     
     if( ! in_array( $blacklist ) ) { 
     wpforms()->process->errors[ $form_data['id'] ][ $field_id ] = esc_html__( 'Email domain not accepted!', 'wpforms' );
     return;
     }
    }
    add_action('wpforms_process_validate_email', 'wpf_dev_blacklist_domains', 10, 3 );

    You can replace [email protected] with the specific email address that you would like to block.

    In case it helps, here’s our tutorial with the most common ways to add custom code like this.

    For the most beginner-friendly option in that tutorial, I’d recommend using the Code Snippets plugin.

    Could you please give the code a try and let me know if that works for you?

    Thanks!

    • This reply was modified 4 years, 9 months ago by Prashant Rai.
Viewing 1 replies (of 1 total)
  • The topic ‘Blacklist email addresses’ is closed to new replies.