Select Page

I use a contact form on my website to automatically add the contact to my CRM, in addition to sending me an email on all contact form submissions on the site. I had Recaptcha set, but I found that bots have gotten much better at busting the captcha, and I had started getting a ton of spam in my CRM.

I have been around WordPress and have seen Akismet in every installation, but I didn’t realize they had an API(https://akismet.com/developers/comment-check/) that would help me so much. I still send the email to myself for every form submission(you don’t have to), and I have a marked_spam variable in the email to see if it was marked as Spam or not, but I only add the contact to the CRM if it is not marked spam by Akismet.

public function checkAkismet(Request $request)
    {
        $data = array(
            'blog' => $request->root(),
            'blog_lang' => 'en',
            'blog_charset' => 'UTF-8',
            'user_ip' => $request->ip(),
            'user_agent' => $request->header('User-Agent'),
            'referrer' => $request->header('referer'),
            'permalink' => $request->url(),
            'comment_type' => 'contact-form',
            'comment_author' => $request->input('first_name').' '.$request->input('last_name'),
            'comment_author_email' => $request->input('email'),
            'comment_content' => $request->input('message'),
            'api_key' => config('services.akismet.api_key')
        );
        $client = new Client([
            'base_uri' => 'https://rest.akismet.com/1.1/',
            'headers' => [
                'User-Agent' => 'WordPress/4.4.1 | Akismet/3.1.7',
            ],
        ]);

        $response = $client->post('comment-check', [
            'form_params' => $data,
        ]);

        $body = $response->getBody();

        return $body == 'true';
    }

And then I use it in my controller like this:

public function postContact(ContactRequest $request)
    {
        $is_spam = $this->checkAkismet($request);
        $request->request->add(['marked_spam' => $is_spam]);
        Contact::create($request->all());
        Mail::to('[email protected]')->send(new \App\Mail\ContactRequest($request->all()));
        if(!$is_spam) {
            AddToCRM::dispatch($request->all());
        }
        return redirect()->back()->with('success','Thanks for reaching out. We will be in touch shortly!');
    }

For me personally the fee to use Akismet is worth it, because I was having to go into my CRM with each spam submission and delete contacts and accounts and the time saved doing this more than makes up for the fee.

Hopefully this will help you to combat your contact spam as well!