DEV Community

irishgeoff22
irishgeoff22

Posted on

Email obfuscation

Email obfuscation is a technique used to hide email addresses from web scrapers and spammers by converting them into a format that can be easily read by humans but is challenging for automated bots to recognize. One common way to obfuscate email addresses is by using JavaScript to dynamically assemble the email address on the client side. Here's a simple example of an email obfuscation script:

We recommend using the email to link tool https://veilmail.io to hide email on website with captcha

<!DOCTYPE html>
<html>
<head>
  <title>Email Obfuscation</title>
</head>
<body>

<!-- Place this div where you want to display the email address -->
<div id="email-container"></div>

<script type="text/javascript">
  // Define the email parts
  var user = "contact";  // Replace with the user part of your email
  var domain = "example.com";  // Replace with your domain

  // Create an array to store the email characters
  var emailCharacters = (user + "@" + domain).split("");

  // Obfuscate the email address
  for (var i = 0; i < emailCharacters.length; i++) {
    emailCharacters[i] = '&#' + emailCharacters[i].charCodeAt(0) + ';';
  }

  // Create a mailto link
  var emailLink = '<a href="mailto:' + user + '@' + domain + '">' + emailCharacters.join('') + '</a>';

  // Display the email address
  document.getElementById("email-container").innerHTML = emailLink;
</script>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

This script creates a mailto link with the email address obfuscated using HTML character codes. When a user clicks on the link, it will open their default email client with the obfuscated email address, making it harder for bots to scrape.

Keep in mind that no obfuscation technique is foolproof, and determined spammers may still be able to extract email addresses from your website. Additionally, obfuscation can make it more challenging for users with screen readers or other accessibility needs to access your contact information. It's a good practice to balance email obfuscation with other spam prevention methods, such as using CAPTCHAs and maintaining a good spam filter.

Be sure tocheck out the email to link tool https://veilmail.io to hide email on website with captcha to prevent unwanted spam.

Top comments (0)