Skip to main content

Configuration

You’ll find the settings in the back end under System → Settings → Anti-SPAM. Without any changes the bundle works with sensible defaults.

SettingDescription
Disable Anti-SPAMTurns off the check for all forms.
Grey zone thresholdFrom this score on, a submission is considered suspicious. Default: 5
Spam thresholdFrom this score on, the submission is silently discarded. Default: 10
Grey zone actionDon’t send, show notice (default) or Send, mark subject with “[SPAM?]”
Notice textShown above the submit button in the grey zone. Insert tags such as {{email::info@example.com}} are allowed. Empty = default text.
Custom rulesRegex rules with points, see below.

Decision

ScoreResult
below the grey zone (default < 5)processed normally
grey zone (default 5–9)depending on the setting: show the notice and don’t send, or send with “[SPAM?]” in the subject
spam (default ≥ 10)silently discarded; redirect to the same page, so it looks like a success to bots

If the grey zone threshold is higher than the spam threshold, it is automatically lowered to the spam threshold.

Tip

Use a custom notice text with your e-mail address or phone number so that wrongly blocked prospects can still reach you.

Custom rules

Each rule consists of:

ColumnDescription
Field nameName of the form field, e.g. message, or * for all fields
Regex patternPHP regex including delimiters, e.g. /viagra|casino/i
PointsScore points on a match

Invalid patterns are rejected on save, incomplete rows are ignored. Limits apply to protect against expensive patterns, see Checks. On Contao 4.13 and 5.3 this requires the MultiColumnWizard (see Requirements).

Both widgets store the same structure, so existing rules should survive an update from Contao 5.3 to 5.7 (not tested in the browser).

Configuration via config.yaml

Like all Contao settings, the values are stored in system/config/localconfig.php – not in the database. If this file is read-only (e.g. deployments without a writable file system), nothing can be saved in the back end. This affects all Contao settings, not just this bundle.

For such installations, set the values in config/config.yaml (works in Contao 4.13 to 6.x):

contao:
    localconfig:
        anti_spam_disable: false
        anti_spam_hint_threshold: 5
        anti_spam_block_threshold: 10
        anti_spam_suspicious_action: hint   # or: flag
        anti_spam_hint_text: 'Please contact us directly at {{email::info@example.com}}.'
        anti_spam_rules:
            - { field: '*', pattern: '/viagra|casino/i', points: 5 }
            - { field: 'message', pattern: '/\bseo services\b/i', points: 3 }
Warning
  • Values from config.yaml override the back-end settings. Contao automatically locks the affected fields in the back end and marks them with an info icon.
  • Regex patterns set here are not validated on save. Invalid patterns are skipped at runtime and reported as a warning in the Contao system log at most once per day.
  • Clear the cache after changes: vendor/bin/contao-console cache:clear

System log

Suspicious submissions are logged in the Contao system log – with form, score, decision and reasons, but without form contents. Entries appear in the language of the page the form was submitted on. Use them to fine-tune the thresholds based on real submissions.