Archive for the ‘Spam’ Category

Is it spam? (According to Akismet)

Saturday, June 5th, 2010 by Phillip Napieralski

Akismet is perhaps the most popular form of spam protection today. I made a form so you can see the sort of things that Akismet thinks is spam. Check it out.

Things to look for

Spelling Errors?
Check out spam case 1, “sunlasses shop.” The biggest reason for its classification is the mispelled word “somwhere.” Fix the spelling and test it again. It should show up as “ham” now! The original is an actual spam comment I received on this blog a couple days ago, I changed the links and e-mail slightly, however.

Check out spam case 2, “Jim Boots.” It’s obvious if someone posted this comment on your blog that they are simply trying to promote a product. However, what makes it spammy is simply because the hyperlink to Mr. Boot’s website also has the hyperlink text as the website. If you click on ham case 1, you will notice the hyperlink text says “here” instead of “,” and is no longer identified as spam. Although, interestingly, if you change where the hyperlink actually goes to in the original spam case (eg, leave the hyperlink text as www.cowboyboots…, but change the link to go to a naughty site or something)

Finally, look at ham case 2, “Trustworthy Guy.” This is the perfect comment: solid spelling, grammar is good enough, and no hyperlinks at all. This is simply an example of what a comment should look like!


If you want your comments to show up on blogs (or whatever Akismet is safeguarding), it might be helpful to test it with this form before submitting your comment.

Spam-proof Contact Form with PHP/Akismet

Sunday, May 9th, 2010 by Phillip Napieralski

Check out the demo

This is in addition to my previous post about creating a simple contact form. This post will utilize the Akismet service to classify some messages as spam.

The Prerequisites

To follow this tutorial, I assume you already have a simple contact form in place.

Akismet PHP Library

The folks at Aching Brain created a nifty PHP class to make utilizing the Akismet service easier. Download this library then put it in the same directory as your contact form file (Download mirror: AkismetPHPClass).

There are implementations available in other languages as well.


This code will completely replace the PHP code from the previous post. However, I assume the HTML used is unchanged.

First, include the Akismet library:

require "Akismet.class.php";

Now, create a more generic function for sending an email:

function send_mail( $name, $email, $website, $ip, $is_spam, $message)
  		$subject = '';
  		if( $spam == true )
  			$subject = "[SPAM?]"; 
  		$subject .= "[] E-mail received from ".$author_name."//".$author_email."//".$ip;
  		mail( "", $subject, 
		$author_name.", ".$author_email.", ".$author_website. ".\r\n\r\n".$message);

If the $is_spam parameter is set to true, we simply prepend “[SPAM?]” at the beginning of the subject line. This allows us to see right away what it is in our inbox. Further, you could create an e-mail filter to automatically put these messages in a different e-mail folder.

Now, we have to set-up the Akismet class. This will require a WordPress API Key. If you don’t have one, it’s easy and free to get one.

		$wp_key = 'xXxXxXxXxXxX';
		$our_url = '';
		$name = $_POST['name'];
		$email = $_POST['email'];
		$website = $_POST['website'];
		$message = $_POST['message'];
		$ip = $_SERVER['REMOTE_ADDR'];
		$akismet = new Akismet($our_url, $wp_key);
		send_mail( $name, $email, $website, $ip, $akismet->isCommentSpam(), $message);

That’s it! Now if a line of spammers hits your contact form, you have a safe guard against it. If you have questions about this piece of code or anything else, feel free to leave a comment!

In conlusion, Akismet is the best!