Is there a way I can use PHP to check if my email content is spam?

The idea is that before I send mail, I would like to use some code to check the content to see if it is using a spam phrase. Here is a simple code

function isSpam($text)
    $pattern = "/\b(actual|filter|removed|because|it|contained|obscenities)\b/i";

    if(preg_match($pattern, $text, $match))
        return true;
        return false;



  • Is there a way to improve the code, like checking the runtime rather than just checking if it exists?

  • Is there any other plugin or code out there so I don't need to repeat it?

  • Bayesian Spam Filter - All About Inbox? Is this useful as an outbound email filter ?

thanks for the help


source to share

2 answers

you can check any content if it contains any spam messages with a nice plugin called Akismet, it is free and used by most CMS and blogging apps like wordpress etc.

check the link

the library itself is very easy to implement, just download the library from the website and use the provided API from the documentation. and you're good to go. I found this to be very effective for me.



If your server is equipped with SpamAssassin, you can use this API: (it may be a little outdated, but it is not would be an insurmountable task to bring it up to date).

I am sure that other anti-spam tools will have similar capabilities.



All Articles