Skip to content

Instantly share code, notes, and snippets.

@neo22s
Last active January 21, 2017 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neo22s/de766d3e0df974c6253c3b3435691790 to your computer and use it in GitHub Desktop.
Save neo22s/de766d3e0df974c6253c3b3435691790 to your computer and use it in GitHub Desktop.
PHPMailer Spamassassin Score
<?
/**
* Example how to use it in PHPMailer
*/
//once initiated PHPMAiler before you can get_spam_socre you need to execute preSend() since is the way to get the RAW email that will be sent.
$mail->preSend();
$spam_score = get_spam_score($mail->getSentMIMEMessage());
if ($spam_score >= 5 OR $spam_score === FALSE)
{
echo "Please review your email. Got a Spam Score of " . $spam_score;
}
/**
* returns the spam score of a raw email using api from postmarkapp
* @param string $raw_email entire RAW email with headers etc....
* @return numeric/false spam score or FALSE is something went wrong....
*/
function get_spam_score($raw_email)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://spamcheck.postmarkapp.com/filter');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('email' => $raw_email,'options'=>'short')));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$response = curl_exec($ch);
//something went wrong with the request
if(empty($response) || curl_error($ch) || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200){
curl_close($ch);
return FALSE;
}
curl_close($ch);
$score = json_decode($response);
if ($score->success == TRUE AND is_numeric($score->score))
return $score->score;
else
return FALSE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment