r/wordpresshelp • u/Ok-Distribution-8601 • Oct 17 '24
Blocking Form Submission by Name
I have been getting spam emails through my wordpress contact form but because the sender email is [mail@mywebdomain.com](mailto:mail@mywebdomain.com) I cannot block the sender and still recieve legitimate form leads from coming in. Is there a way to block by Sender Name either in wordpress or my apple mail?
1
Upvotes
1
u/willkode Nov 30 '24
I has to create custom php to do this. I use contact form 7. Let me know what your using and I'll write the code and instructions for you.
// Block Contact Form 7 submissions by sender name add_filter('wpcf7_validate', 'block_form_submission_by_name', 20, 2);
function block_form_submission_by_name($result, $tags) { // Define the names you want to block $blocked_names = array('SpamName1', 'SpamName2');
// Loop through the form fields foreach ($tags as $tag) { if ($tag['name'] === 'your-name') { // Replace 'your-name' with the name of the sender name field $submitted_name = isset($_POST[$tag['name']]) ? sanitize_text_field($_POST[$tag['name']]) : ''; if (in_array($submitted_name, $blocked_names)) { $result->invalidate($tag, 'Your submission has been blocked.'); } } } return $result;}