We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29076
    • 615 Posts
    I have a contact form based on smtp/Gmail. But there is a spam-robot sending in the name Timothywaw that I want to be blocked as sender.

    Is this possible?

    I use a Gmail-account as sender/smtp host/adresse, so all emails goes through the folder Sendt in that account. But it's not possible to make filters to the Sendt folders, so I figure I have to set in the Modx Formit setup.

    Data:
    Modx Revo 2.7.0
    Formit latest.

    Code:
    [[!FormIt?
            &hooks=`spam,email,redirect,formItAutoResponder`
            &emailTpl=`EpostmeldingTmpl`
            &emailTo=`[email protected]`
            &emailReplyToo=`[[+email]]`
            &emailSubject=`Melding fra kontaktskjemaet på verketyoga.no`
            &emailFromName=`[[+name]]`
            &redirectTo=`200`
            &store=`1`
            &clearFieldsOnSuccess=`1`
            &fiarTpl=`kontaktMelding-confirmation`
            &fiarFrom=`[email protected]`
            &fiarFromName=`[email protected]`
            &validate=`name:required,
              email:email:required,
              message:required:stripTags`
          ]]
          <form class="cmxform" id="contactForm" action="[[~[[*id]]]]" method="post">
            <input type="hidden" name="nospam:blank" value="[[+fi.nospam]]" />
      I think, thererfor I am! But what I am, and why...?
      • 42541
      • 18 Posts
      You can use FormIt &preHooks:

      [[!FormIt? &preHooks=`stopTheSpammers`]]


      and stopTheSpammers snippet code:

      $email = $hook->getValue('email'); // get email from a form that is actually sending
      $allFormFields = $hook->getValues();  // get all fields from that form to an array
      if (...) {
      ... // your filter code
      $errorMsg = 'Got ya spammer!';
      $hook->addError('user',$errorMsg);
      return false;
      } else {
      return true;
      }
      
      


      return false stops the form and return true is continuing formit script.
      https://docs.modx.com/extras/revo/formit/formit.hooks/#FormIt.Hooks-UsingpreHooks

      personally i would recommend some captcha systems i.e. google recaptcha.
      https://developers.google.com/recaptcha/docs/v3