Note:
If you are using the Akismet API, it is recommended you build a system to
enter data back into the API either by submitting missed spam, or by
submitting false positives. While not strictly required, passing data back
using the API will allow the service to learn from its mistakes, and will
ensure the service stays relevant for your needs.
try { $apiKey = 'AABBCCDDEEFF'; $akismet = new Services_Akismet2('http://blog.example.com/', $apiKey); if ($akismet->isSpam($comment)) { // rather than simply ignoring the spam comment, it is recommended // to save the comment and mark it as spam in case the comment is a // false positive. } else { // save comment as normal comment } } catch (Services_Akismet2_InvalidApiKeyException $keyException) { echo 'Invalid API key!'; } catch (Services_Akismet2_HttpException $httpException) { echo 'Error communicating with Akismet API server: ' . $httpException->getMessage(); } catch (Services_Akismet2_InvalidCommentException $commentException) { echo 'Specified comment is missing one or more required fields.' . $commentException->getMessage(); }