tvaliasek/simple-php-akismet

Simple class for check comment or contact form spam against Akismet API

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/tvaliasek/simple-php-akismet

0.1.0 2020-09-06 23:31 UTC

This package is auto-updated.

Last update: 2025-10-09 18:36:59 UTC


README

Very simple modern PHP implementation of Akismet spam check service.

Install

composer require tvaliasek/simple-php-akismet

Use

use SimpleAkismet\Client;
use SimpleAkismet\DataObject\Message;
use SimpleAkismet\Exception\AkismetException;
use SimpleAkismet\Exception\InvalidKeyException;
use SimpleAkismet\Exception\InvalidStatusCodeException;

/* 
* Client covers all four API methods: 
* verifyKey, checkSpam, submitSpam and submitHam 
*/
$client = new Client(
    'yourAkismetApiKey',
    'https://www.example.com/',
    new \GuzzleHttp\Client()
);

$message = (new Message())
    ->setBlog('https://www.example.com/')
    ->setCommentAuthorEmail('john@doe.com')
    ->setCommentContent('Cheap viagra for sale on: www.foo.com')
    ->setCommentDateGmt(new \DateTime());
    // all available fields has their own setter and getter

try {
    if ($client->checkSpam($message)) {
        // do something with spam message
    }
} catch (AkismetException | InvalidKeyException | InvalidStatusCodeException $e) {
    // ...
}