PHP Requires Chilkat v11.0.0+
PHP
Request a SpamAssassin score for a sample email
See more Email Object Examples
Submit a synthetic message to Postmark’s SpamCheck endpoint. The service receives the complete MIME you provide. Request a short result and check both the HTTP status and the API success field before reading the numeric score. SpamCheck API documentation.
Chilkat PHP Downloads
<?php
use Chilkat2\Email;
use Chilkat2\Http;
use Chilkat2\HttpResponse;
use Chilkat2\JsonObject;
$success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
$email = new Email();
$email->From = 'Workshop team <events@example.com>';
try {
$email->AddTo('Alex Rivera', 'alex@example.net');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$email->Subject = 'Workshop registration';
$email->Body = 'Your workshop registration is confirmed.';
$request = new JsonObject();
$request->UpdateString('email', $email->GetMime());
$request->UpdateString('options', 'short');
$http = new Http();
$http->RequireSslCertVerify = true;
$resp = new HttpResponse();
try {
$http->HttpJson('POST', 'https://spamcheck.postmarkapp.com/filter', $request, 'application/json', $resp);
$success = true;
} catch (\Chilkat2\Exception $e) {
$success = false;
}
if ((!$success) || ($resp->StatusCode != 200)) {
echo 'SpamCheck request failed. HTTP ', $resp->StatusCode, "\n";
exit;
}
$result = new JsonObject();
try {
$result->Load($resp->BodyStr);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
if (!$result->BoolOf('success')) {
echo $result->StringOf('message'), "\n";
exit;
}
echo 'SpamAssassin score: ', $result->StringOf('score'), "\n";