Last active
January 21, 2017 22:44
-
-
Save neo22s/de766d3e0df974c6253c3b3435691790 to your computer and use it in GitHub Desktop.
PHPMailer Spamassassin Score
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* 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