Spam in Contact Form 7 ist nervig. Hier sind effektive Methoden, um Spam zu stoppen – ganz ohne nervige Captchas.
1. Honeypot-Feld (Am effektivsten!)
Ein unsichtbares Feld, das nur Bots ausfüllen:
/* Im Contact Form 7 Formular: */
[text honeypot class:honeypot]
/* CSS um es zu verstecken: */
.honeypot {
position: absolute;
left: -9999px;
opacity: 0;
height: 0;
}
Dann in functions.php prüfen:
add_filter('wpcf7_validate', 'honeypot_check', 10, 2);
function honeypot_check($result, $tags) {
$honeypot = isset($_POST['honeypot']) ? $_POST['honeypot'] : '';
if (!empty($honeypot)) {
$result->invalidate('', 'Spam erkannt');
}
return $result;
}
2. Zeit-basierte Validierung
Menschen brauchen Zeit zum Ausfüllen, Bots nicht:
// Hidden field mit Timestamp:
[hidden timestamp default:get]
add_filter('wpcf7_validate', 'time_check', 10, 2);
function time_check($result, $tags) {
$timestamp = intval($_POST['timestamp']);
$now = time();
// Wenn weniger als 3 Sekunden vergangen sind
if (($now - $timestamp) < 3) {
$result->invalidate('', 'Zu schnell ausgefüllt');
}
return $result;
}
3. Bestimmte Keywords blockieren
add_filter('wpcf7_spam', 'block_spam_keywords', 10, 2);
function block_spam_keywords($spam, $submission) {
$message = $submission->get_posted_data('your-message');
$spam_keywords = array(
'viagra', 'casino', 'crypto', 'bitcoin',
'SEO services', 'link building'
);
foreach ($spam_keywords as $keyword) {
if (stripos($message, $keyword) !== false) {
return true; // Ist Spam
}
}
return $spam;
}
4. Absender-Domain prüfen
add_filter('wpcf7_validate_email*', 'block_spam_domains', 20, 2);
function block_spam_domains($result, $tag) {
$email = isset($_POST[$tag->name]) ? $_POST[$tag->name] : '';
$blocked_domains = array(
'tempmail.com', 'guerrillamail.com',
'mailinator.com', '10minutemail.com'
);
$domain = substr(strrchr($email, '@'), 1);
if (in_array($domain, $blocked_domains)) {
$result->invalidate($tag, 'Diese E-Mail-Domain ist nicht erlaubt.');
}
return $result;
}
5. Flamingo für Logging
Installiere das Plugin "Flamingo" – es speichert alle Einträge in der Datenbank, auch die als Spam markierten. So kannst du Muster erkennen.
Kombiniere mehrere Methoden für maximalen Schutz – ein Honeypot allein stoppt 90% des Spams!