Anti-Spam Measures for Contact Forms on International Websites
Introduction
When running a WordPress website for an international audience, it’s common to face an overwhelming number of spam messages through your contact forms. Especially for English-language or multilingual sites, spam bots often flood forms with unwanted content. Ignoring this problem increases management workload and risks missing important customer inquiries. This article, written in a diary-style narrative, shares practical ways to implement anti-spam measures for contact forms on international WordPress sites.
Step-by-Step Guide
There are several approaches to blocking spam. Combining them yields the best results.
- Implement Google reCAPTCHA
Adding Google reCAPTCHA helps block automated submissions. Using reCAPTCHA v3 provides invisible protection without requiring user interaction.
Google reCAPTCHA - Use the Akismet Anti-Spam Plugin
Akismet automatically analyzes form submissions and filters out spam messages. It’s one of the most reliable WordPress solutions. - Leverage Contact Form 7’s Built-in Features
Contact Form 7 allows adding simple spam-prevention fields, such as a math quiz or challenge question. This blocks many bots. - Block Specific IPs or Email Domains
By adding custom code infunctions.php
, you can reject submissions from suspicious sources.
Code Example: Blocking Spam Emails by Domain
This PHP code blocks form submissions from certain email domains in Contact Form 7.
Here is the code:
// Block specific email domains
add_filter('wpcf7_validate_email*', 'block_spam_domain', 20, 2);
function block_spam_domain($result, $tag) {
$type = $tag['type'];
$name = $tag['name'];
if ('email' == $type || 'email*' == $type) {
$email = isset($_POST[$name]) ? trim($_POST[$name]) : '';
if (strpos($email, '@example.com') !== false) {
$result->invalidate($tag, 'This domain is not allowed.');
}
}
return $result;
}
Key Points
- Replace
@example.com
with the spam domain you want to block. - You can add multiple rules to cover different domains or patterns.
Testing & Practical Use
- After adding the code, test by submitting a form with the blocked domain to ensure the restriction works.
- Combine this with reCAPTCHA and Akismet for maximum protection.
- While it’s impossible to eliminate spam entirely, you can reduce it by over 90%.
Conclusion
Spam protection is essential for international WordPress sites. By combining reCAPTCHA, Akismet, Contact Form 7 features, and custom code, you can drastically reduce spam while keeping your site user-friendly. The goal is to balance security with usability so real customer inquiries are never lost.
コメント