Possible Duplicate:
How can I prevent spam on sites which I control?

I'm looking for something like spam-assassin or similar, except it only focuses on the message rather than inspecting an entire email header.

It doesn't even need to be really fancy, just do the classification of messages. In theory we could provide meta-data such as IP.

I'm doing this because I want an feedback forum without authentication or recaptcha or having to put every email in the "pending" bin before it's published.

marked as duplicate by user6901 Aug 29 '12 at 1:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Have you considered Akismet? It's excellent at catching spam.

  • Yeah and I've also looked at sblam-- but I'd like to do something that doesn't involve third-party api latency. – Incognito Dec 3 '11 at 18:33
  • 1
    Nothing will be as good as a hosted service like Akismet which analyzes thousands of posts per second across thousands of sites on the internet. The AI/Machine Learning aspects are only possible when used at a large scale. I think you should try to build your application in a way that queries Akismet asynchronously if you're worried about latency - design it in a way that the user doesn't have to wait for you to query Akismet. – Max Dec 4 '11 at 20:07

You can create your own spam filter classes and use it.

I use following class to detect spam on comments:

 class CommonFunctions{

        private $spam_array = array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'

        *find whether a string contains html
        *@param string
        *@return boolean
        public function containHtml($data){

            if(strlen($data) != strlen(strip_tags($data))){
                return true;

            return false;

        //function end

        public function isOK($data){
                        return true;    
            return false;
        *find whether a string contains spam
        *@param string
        *@return boolean
        public function containSpam($data){
            foreach($this->spam_array as $spam_word){
                //echo "<br>Data is $data Word is $spam_word ".stripos($data,$spam_word)."<br/>";

                    return true;


            return false;

        //function end

        function cusFnmatch($needl,$check_string){

            if (!function_exists('fnmatch')) {
                define('FNM_PATHNAME', 1);
                define('FNM_NOESCAPE', 2);
                define('FNM_PERIOD', 4);
                define('FNM_CASEFOLD', 16);

                function fnmatch($pattern, $string, $flags = 0) {
                    return pcre_fnmatch($pattern, $string, $flags);


                function pcre_fnmatch($pattern, $string, $flags = 0) {
                    $modifiers = null;
                    $transforms = array(
                        '\*'    => '.*',
                        '\?'    => '.',
                        '\[\!'    => '[^',
                        '\['    => '[',
                        '\]'    => ']',
                        '\.'    => '\.',
                        '\\'    => '\\\\'

                    // Forward slash in string must be in pattern:
                    if ($flags & FNM_PATHNAME) {
                        $transforms['\*'] = '[^/]*';

                    // Back slash should not be escaped:
                    if ($flags & FNM_NOESCAPE) {

                    // Perform case insensitive match:
                    if ($flags & FNM_CASEFOLD) {
                        $modifiers .= 'i';

                    // Period at start must be the same as pattern:
                    if ($flags & FNM_PERIOD) {
                        if (strpos($string, '.') === 0 && strpos($pattern, '.') !== 0) return false;

                    $pattern = '#^'
                        . strtr(preg_quote($pattern, '#'), $transforms)
                        . '$#'
                        . $modifiers;

                    return (boolean)preg_match($pattern, $string);
            return fnmatch($needl,$check_string);


and i'll check for spam like this,

include_once "class.commonfunctions.php";

$cmn=new CommonFunctions();
    return false;

 //proceed with insert

  • I don't know why i've given downvote, the questioner doesn't like to use third party software so i suggested one class which will block urls and spam words if set. How this qualify for a down vote? – VKGS Jan 6 '12 at 7:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.