Page 1 of 1

Prevent spam mails using AKISMET in non wordpress sites

PostPosted: Mon Feb 14, 2011 6:57 am
by krishnaprasad
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 :)

Re: Prevent spam mails using AKISMET in non wordpress sites

PostPosted: Mon Feb 14, 2011 10:03 pm
by tvjames
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.