February 20, 2024 5:08 am

How to Hide your Email Address from spam bots

As a Web Developer you have to mention your email address in contact us pages or any pages and now days spam bots can easily copy that emails and send spam promotions on your email address, so in this article I am going to show you few settings in which no any spam bot can get your actual email and failed to spam your inbox. Have a look on blow explanation and integrate in your web applications.

Hide your Email Address from spam bots

How spammers work to get your email address:

Mostly spammers look for “@” sign in your HTML page and grab words before and after “@” sign like [email protected] and that email address match with there pattern-search and store it in there database and use it for spamming.

1. Hide your email with CSS

  email-data::after {
    content: attr(mail-domain);
  email-data::before {
    content: attr(mail-user);

<!-- Set mail-user and mail-domain as your 
       email username and domain respectively --> 

<email-data mail-user="john" mail-domain="gmail.com">@</email-data>

Here I used  ::before and ::after pseudo-elements in CSS to insert email id and domain in mail-data element using this method only shows email in browser bot cannot see your email address.

An other CSS example to hide actual email.

   display: none;

<!-- You can add any thing between <span id="spammmmer"> but they'll stay hidden and no one can see that extra words-->
phpgang<span id="spammmmer">RemoveMe</span>@gmail<span id="spammmmer">HideMe</span>.com

Above example can hide extra tags text with CSS attribute display: none; and show original email on webpage but spammers get wrong address and not gonna send email on that email.

2. Render Email through JavaScript:

<a href = "mailto:info__ATphpgang__DOTcom" 
   onclick = "this.href=this.href
>Contact Us</a>

If you want to create mailto hyperlink and don’t want to spammers get your email address then above example is the best for you and it works on your onclick event replace __AT with “@” and __DOT with “.” to complete proper email address. Example: Contact Us.

If you are using WordPress there is a predefined function in WordPress to handle spam bots.

    echo antispambot("[email protected]"); 

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:

One response to “How to Hide your Email Address from spam bots”

  1. Usama Ejaz says:

    Nice snippents 🙂

    David Walsh’s email encoding function is nice too.

    function encode_email($e) {
    for ($i = 0; $i < strlen($e); $i++) { $output .= '&#'.ord($e[$i]).';'; }
    return $output;

    echo(encode_email('[email protected]'));

Leave a Reply

Your email address will not be published. Required fields are marked *