Prevent spam mails using AKISMET in non wordpress sites

Programming for Search Engines 101. An area for avid PHP and .NET developers to chat about Programming techniques and how to make better use of search engines.

Moderator: Moderators

Prevent spam mails using AKISMET in non wordpress sites

Postby krishnaprasad » Mon Feb 14, 2011 6:57 am

SPAM mails have always been an issue for most of our clients.

We used to make use of the standard SPAM filtering code developed internally at Techwyse Intl.

Instead we can now make use of the standard AKISMET API classes which in turn would gauarantee better results I presume as it's already a well know SPAM filtering routine.


The code can be implemented in the following manner.

Step 1: Download class.microakismet.inc.php and include that in your mail action script.

Step 2: Generate the API key for the client from Akismet website and this needs to be mentioned in the following code snippet

$akey='<akismet key>';
$apage= '<CORRESPONDING PAGE NAME>';
$aver='askapache.com/1.0';
$akismet = new MicroAkismet( $akey, $apage, $aver );


Step 3: Then we need to populate the array variable that gets sent to Akismet server for SPAM checking as follows

//data to Akismet
$vars = array();
foreach(array_keys($_SERVER) as $skey){
if((substr($skey, 0, 5) == "HTTP_") && !empty($_SERVER[$skey]))
$vars[str_replace('HTTP_','',$skey)]=$_SERVER[$skey];
}

$vars["user_ip"] = $_SERVER["REMOTE_ADDR"];
$vars["user_agent"] = $_SERVER["HTTP_USER_AGENT"];
$vars["comment_content"] = $_POST["comments"];
$vars["comment_author"] = $_POST["fname"];
$vars["comment_author_email"] = $_POST["email"];
$vars["comment_type"] = 'comment';
$vars['permalink'] = '<DOMAIN NAME>'.$_SERVER['REQUEST_URI'];
$vars['referrer'] = $_SERVER['HTTP_REFERER'];
$vars['phone_number'] = $_POST['phoneno'];
$vars['organization'] = '';


Step 4: Now invoke the AKISMET class spam check method and do the needful
if($akismet->check( $vars ))
{
//Redirect to index page
}
else
{
//Mail sending script
}

We have implemented this for one of our clients and seems like it's working fine. Cheers to our little buddies at AKISMET for providing the API :)
krishnaprasad
 

Re: Prevent spam mails using AKISMET in non wordpress sites

Postby tvjames » Mon Feb 14, 2011 10:03 pm

Now that's a good find KP.

Though it won't guarantee 100% SPAM free mail accounts, am pretty sure it would provide much better results.

Hoping that this would be made a standard from now on for all our projects.
tvjames
 


Return to Programming

Who is online

Users browsing this forum: No registered users and 11 guests