<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Phillip Napieralski &#187; Akismet</title>
	<atom:link href="http://blog.pnapieralski.com/tag/akismet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pnapieralski.com</link>
	<description>Programmer, Engineer, Researcher.</description>
	<lastBuildDate>Tue, 20 Dec 2011 16:41:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Spam-proof Contact Form with PHP/Akismet</title>
		<link>http://blog.pnapieralski.com/php/spam-proof-contact-form-with-php-akismet/</link>
		<comments>http://blog.pnapieralski.com/php/spam-proof-contact-form-with-php-akismet/#comments</comments>
		<pubDate>Sun, 09 May 2010 21:55:20 +0000</pubDate>
		<dc:creator>Phillip Napieralski</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Spam]]></category>
		<category><![CDATA[Akismet]]></category>
		<category><![CDATA[Spam Prevention]]></category>

		<guid isPermaLink="false">http://blog.pnapieralski.com/?p=36</guid>
		<description><![CDATA[<a href="http://pnapieralski.com/contact.php">Check out the demo</a>

This is an addition to my previous post to create a <a href="http://blog.pnapieralski.com/php/simple-contact-us-form-with-php/">simple contact form</a>. This post will utilize the <a href="http://akismet.com/">Akismet</a> service to classify some messages as spam.]]></description>
			<content:encoded><![CDATA[<p><a href="http://pnapieralski.com/tuts/isitspam">Check out the demo</a></p>
<p>This is in addition to my previous post about creating a <a href="http://blog.pnapieralski.com/php/simple-contact-us-form-with-php/">simple contact form</a>. This post will utilize the <a href="http://akismet.com/">Akismet</a> service to classify some messages as spam.</p>
<h2>The Prerequisites</h2>
<p>To follow this tutorial, I assume you already have a <a href="http://blog.pnapieralski.com/php/simple-contact-us-form-with-php/">simple contact form</a> in place.</p>
<h2>Akismet PHP Library</h2>
<p>The folks at <a href="http://www.achingbrain.net">Aching Brain</a> created a nifty PHP class to make utilizing the Akismet service easier. <a href="http://www.achingbrain.net/stuff/php/akismet">Download this library</a> then put it in the same directory as your contact form file (Download mirror: <a href='http://blog.pnapieralski.com/wp-content/uploads/2010/05/AkismetPHPClass.zip'>AkismetPHPClass</a>).</p>
<p>There are implementations available in <a href="http://akismet.com/development/">other languages</a> as well.</p>
<h2>The PHP</h2>
<p>This code will completely replace the PHP code from the previous post. However, I assume the HTML used is unchanged.</p>
<p>First, include the Akismet library:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require &quot;Akismet.class.php&quot;;
</pre>
<p>Now, create a more generic function for sending an email:</p>
<pre class="brush: php; title: ; notranslate">
function send_mail( $name, $email, $website, $ip, $is_spam, $message)
  {
  		$subject = '';
  		if( $spam == true )
  			$subject = &quot;[SPAM?]&quot;;
  		$subject .= &quot;[Your_site.com] E-mail received from &quot;.$author_name.&quot;//&quot;.$author_email.&quot;//&quot;.$ip;

  		mail( &quot;send_to_this_address@to.com&quot;, $subject,
		$author_name.&quot;, &quot;.$author_email.&quot;, &quot;.$author_website. &quot;.\r\n\r\n&quot;.$message);
}
</pre>
<p>If the $is_spam parameter is set to true, we simply prepend &#8220;[SPAM?]&#8221; 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 <a href="http://mail.google.com/support/bin/answer.py?hl=en&#038;answer=6579">e-mail filter</a> to automatically put these messages in a different e-mail folder.</p>
<p>Now, we have to set-up the Akismet class. This will require a WordPress API Key. If you don&#8217;t have one, <a href="http://en.wordpress.com/api-keys/">it&#8217;s easy and free to get one</a>.</p>
<pre class="brush: php; title: ; notranslate">
	if(isset($_POST['action']))
	{
		$wp_key = 'xXxXxXxXxXxX';
		$our_url = 'http://www.your_website.com';

		$name = $_POST['name'];
		$email = $_POST['email'];
		$website = $_POST['website'];
		$message = $_POST['message'];
		$ip = $_SERVER['REMOTE_ADDR'];

		$akismet = new Akismet($our_url, $wp_key);
		$akismet-&gt;setCommentAuthor($name);
		$akismet-&gt;setCommentAuthorEmail($email);
		$akismet-&gt;setCommentAuthorURL($website);
		$akismet-&gt;setCommentContent($message);
		$akismet-&gt;setUserIP($ip);

		send_mail( $name, $email, $website, $ip, $akismet-&gt;isCommentSpam(), $message);
	}
?&gt;
</pre>
<p>That&#8217;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!</p>
<p>In conlusion, Akismet is the best!</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Spam-proof+Contact+Form+with+PHP%2FAkismet&amp;link=http://blog.pnapieralski.com/php/spam-proof-contact-form-with-php-akismet/&amp;notes=Check%20out%20the%20demo%0D%0A%0D%0AThis%20is%20an%20addition%20to%20my%20previous%20post%20to%20create%20a%20simple%20contact%20form.%20This%20post%20will%20utilize%20the%20Akismet%20service%20to%20classify%20some%20messages%20as%20spam.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Spam-proof+Contact+Form+with+PHP%2FAkismet&amp;link=http://blog.pnapieralski.com/php/spam-proof-contact-form-with-php-akismet/&amp;notes=Check%20out%20the%20demo%0D%0A%0D%0AThis%20is%20an%20addition%20to%20my%20previous%20post%20to%20create%20a%20simple%20contact%20form.%20This%20post%20will%20utilize%20the%20Akismet%20service%20to%20classify%20some%20messages%20as%20spam.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Spam-proof+Contact+Form+with+PHP%2FAkismet&amp;link=http://blog.pnapieralski.com/php/spam-proof-contact-form-with-php-akismet/&amp;notes=Check%20out%20the%20demo%0D%0A%0D%0AThis%20is%20an%20addition%20to%20my%20previous%20post%20to%20create%20a%20simple%20contact%20form.%20This%20post%20will%20utilize%20the%20Akismet%20service%20to%20classify%20some%20messages%20as%20spam.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-technorati">
			<a href="http://www.shareaholic.com/api/share/?title=Spam-proof+Contact+Form+with+PHP%2FAkismet&amp;link=http://blog.pnapieralski.com/php/spam-proof-contact-form-with-php-akismet/&amp;notes=Check%20out%20the%20demo%0D%0A%0D%0AThis%20is%20an%20addition%20to%20my%20previous%20post%20to%20create%20a%20simple%20contact%20form.%20This%20post%20will%20utilize%20the%20Akismet%20service%20to%20classify%20some%20messages%20as%20spam.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=10&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Spam-proof+Contact+Form+with+PHP%2FAkismet&amp;link=http://blog.pnapieralski.com/php/spam-proof-contact-form-with-php-akismet/&amp;notes=Check%20out%20the%20demo%0D%0A%0D%0AThis%20is%20an%20addition%20to%20my%20previous%20post%20to%20create%20a%20simple%20contact%20form.%20This%20post%20will%20utilize%20the%20Akismet%20service%20to%20classify%20some%20messages%20as%20spam.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Spam-proof+Contact+Form+with+PHP%2FAkismet&amp;link=http://blog.pnapieralski.com/php/spam-proof-contact-form-with-php-akismet/&amp;notes=Check%20out%20the%20demo%0D%0A%0D%0AThis%20is%20an%20addition%20to%20my%20previous%20post%20to%20create%20a%20simple%20contact%20form.%20This%20post%20will%20utilize%20the%20Akismet%20service%20to%20classify%20some%20messages%20as%20spam.&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="http://www.shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.pnapieralski.com/php/spam-proof-contact-form-with-php-akismet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

