DEV Community

irishgeoff22
irishgeoff22

Posted on • Edited on

How To Protect Your Website email Address From Spam

Here are somegooddetails on how to protect your websiteemail address from spam:

  1. Contact Forms with CSRF Protection:
    Implement contact forms on your website with Cross-Site Request Forgery (CSRF) protection to ensure that the form submissions are legitimate. This helps prevent automated bots from exploiting your forms for spam purposes.

  2. Email Obfuscation through JavaScript:
    Utilize JavaScript to dynamically generate the email address in the Document Object Model (DOM) rather than hardcoding it in the HTML source code. This approach can obfuscate the email address, making it more challenging for bots to extract.

   <script>
     document.getElementById('email').innerHTML = 'user' + '@' + 'domain.com';
   </script>
Enter fullscreen mode Exit fullscreen mode
  1. Image-based Email Representation:
    Convert the email address into an image using server-side techniques or client-side libraries. This prevents automated scraping tools from extracting the email address directly from the HTML code.

  2. CSS Techniques for Display:
    Use CSS to hide email addresses by applying styles that make them visually hidden, such as setting the font size to zero or using negative text indentation.

   .hidden-email {
     font-size: 0;
     color: transparent;
   }
Enter fullscreen mode Exit fullscreen mode
  1. CAPTCHAs with API Integration:
    Integrate CAPTCHAs into your forms using APIs like Google's reCAPTCHA. This adds an additional layer of security by ensuring that the form submissions are initiated by human users rather than automated scripts.

  2. Text Replacement through JavaScript:
    Employ JavaScript to replace plain text email addresses with dynamically generated content, utilizing a combination of ASCII characters or other symbols to disguise the email.

   <span id="email"></span>

   <script>
     document.getElementById('email').innerHTML = 'user' + '&#64;' + 'domain.com';
   </script>
Enter fullscreen mode Exit fullscreen mode
  1. Use a Dedicated Email Alias:
    Create a dedicated email alias for website inquiries and use server-side filtering to segregate incoming emails. This way, even if the alias receives spam, it won't impact your primary inbox.

  2. Server-side Email Generation:
    Generate email addresses dynamically on the server side and use client-side requests to retrieve them. This method adds an extra layer of complexity for spambots attempting to harvest email addresses directly from the HTML source.

Remember to regularly review and update your spam protection mechanisms to adapt to evolving spamming techniques and to stay ahead of potential security threats.

PRO TIP: Use VeilMail.io to hide email address from spammers

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay