Green Clook

Banning visitors from sending emails through Contact Form 7

Following on from my previous post, How to stop spam emails being sent through Contact Form 7, sometimes a user may wish to permanently exclude a visitor from submitting information through the plug in. This article tells you how to block a user from sending mail via the form…

The reasons for doing so can be varied – unsolicited marketing mail, hoax enquiries or malicious emails.

What we are going to do is find the user/bots IP address and exclude them from publishing comments.

First of all we’ll need to capture the problematic poster’s IP address. This can be done by adding a piece of code to the contact form. To do so navigate to Contact > Contact Forms from the left hand menu.

Next, select an enquiry form you wish to capture a user’s IP, then click the ‘Mail’ tab in the window that loads:

Scroll down the page and you will see a section titled ‘Message Body’ in this part we need to add the code:

IP: [_remote_ip]

Now when a submission is made, the contents of the email received will include the sender’s IP address.

To ban the poster from using your contact form we need to add it to a blacklist.

Navigate to Settings > Discussion

Now scroll down to ‘Comment Blacklist’ and enter the offending IP address.

Ban Visitors Contact Form 7

It’s important to note that this should only be done if you are sure you do not wish to receive contact from users using this particular IP address. Once the details are entered, the submitter will receive a fail message when hitting the send button.

If you wish to go one step further and ban the IP address from your site this can be done via your cPanel account. In cPanel’s Security tab is an icon titled ‘IP Blocker’ If an IP is entered here anyone attempting to view the website will find it inaccessible.

About The Author

Scott is a UX Designer and Developer at Clook. He’s passionate about UI Design, WordPress Development and Marketing.

Working on the creative, branding and marketing side of Clook. He's involved in creating a variety of digital and print designs for us.

Connect on Linkedin

Clook Logo

Get regular tips, tricks and updates!

Signup today for our awesome newsletter and recieve monthly emails with all sorts of helpful articles on hosting and web development.