How to use Akismet Anti-spam with Contact Form 7

Mike MingardWebLeave a Comment

What is Akismet?

Akismet is an spam filtering service launched back in 2005 by Automattic - the people that created and maintain the WordPress content management system (CMS). You can download the Akismet plugin from the WordPress repository here - it also ships with most fresh WordPress installs (along with the infamous Hello, Dolly!) unless removed by your host.

The main purpose of Akismet is to reduce the number of spam comments posted on WordPress blogs. It does this by collating information from every site that runs Akismet and using what is learnt to prevent future spam. As of writing this blog Akismet has prevented 507,854,175,564 spam comments (a real-time counter can be found on the front page of the Akismet website) and is active on over 5 million websites.

While the main purpose is to prevent spam comments, Akismet can be used to prevent spam email coming through contact forms.

What is Contact Form 7?

Contact Form 7 is a plugin for WordPress. It allows the creation of multiple contact forms that a visitor to the website can use to submit information which is then sent by email to a recipient defined by the website creator.

The plugin was developed, and is still maintained, by Takayuki Miyoshi. While not the easiest form plugin to use, Contact Form 7 has become hugely popular. According to the WordPress repository it is active on over 5 million website and has been downloaded over 160 million times. It continued popularity is helped by its lightweight design and the fact that in its default installation it does not:

  • Use cookies
  • Send any user info to other servers
  • Retain any of the submitted information

How can I integrate them?

The first step is to make sure you have both Contact Form 7 and the Akismet plugin installed and active on your website. You will then need to sign up for an Akismet account.  For commercial use plans start at £8 per month (or £6.67 if you pay annually). This is for one website. If you have a non-commercial site or personal blog there is a 'name your price' option.

Once you have your account and your API key is set up you can move on to integrating the spam protection into Contact Form 7. As mentioned before, Akismet is primarily for preventing spam comments, not form submissions. We do however, have three common contact form fields to which we can attach the Akismet code.

1. Name field

This field would be where the person submitting the form puts their name. By default, Contact Form 7 calls it 'your-name'. To add Akismet protection to this you would add 'akismet:author' to the tag.

Code:

[text* your-name akismet:author]

2. Email field

This is whichever field you ask the submitter to state their email address.

Code:

[email* your-email akismet:author_email]

3. Their website

This is the field when you ask the submitter to enter the URL of their website.

Code:

[text your-url akismet:author_url]

It's important to remember that you don't have to use all three of the above options. Many of the sites we create do not ask for a website URL. The chances of spam being caught are improved if you can use as many of the three as is practical in your forms.

Testing your spam filtering

Once you have your code in place it's important to test that the integration is working. To do this simply fill out the form using the following (which are reserved for testing):

  • Name: viagra-test-123
  • Email: akismet-guaranteed-spam@example.com

If your setup is working the form will return the spam error message, the default being 'There was an error trying to send your message. Please try again later.' It is worth changing this message to something more spam specific while testing as this error message is exactly the same as the default for a more general sending failure.

If you need any help with your WordPress website or have any general questions, please contact us.


About the Author

A picture of the author of this blog

Mike Mingard

Designer


Mike is a designer at Optima Systems. He grew up in West London and now lives by the sea. His first love was music which led to jobs in recording engineering and a number of years as a front of house sound engineer and theatre stage manager. Having been taught the basics of HTML while at university he continued to develop websites as a hobby. It wasn't long before he realised the hobby was the more rewarding pursuit. More about Mike.



More from Mike



Other Posts