go top

Protect email address from spam bots

Protecting your email addresses from spam bots is the thing that you should do after making your web forms using the CAPTCHA verification script. You probably know that spam bots are used to visit your web site pages and extract all email address that can be found there. Usually a regular expression is used to match all email address. Using a simple JavaScript function you can make your email address "invisible" to spam bots but still visible for your web site visitors. I've created a JavaScript function that takes 4 parameters and builds a clickable email link.

<script language="javascript">
function emailantispam(email1, email2, email3, email4){
emailE = email1 + email2 + '@' + email3 + email4;
document.write('<a href="mailto:' + emailE + '">' + emailE + '</a>')
};
</script>


Now, assume that your email address is TomRogers@yahoo.com. When you want to have a clickable email on your web pages you use this:

<a href="mailto:tomrogers@yahoo.com">tomrogers@yahoo.com</a>


However, the email address is listed as a plain text and every spam bot can easily find it out. Using the above JavaScript function you can still have a clickable email address on your web page but spam bots will not be able to find it out. All you need to use is:

<script language="javascript">emailantispam('tom','rogers','yah','oo.com');</script>


The emailantispam() function will build an email address using the 4 parameters you pass to it.

9 Comments to "Protect email address from spam bots"

  • Claudia Rogers

    Claudia Rogers

    November 3, 2014 at 17:49 pm

    Help me, please! The email address is not showing up where I tell it to display. These are the steps I took:

    1 - I save the script below in a separate file called emailasp.js


    <script language="javascript">
    function emailantispam(email1, email2, email3, email4){
    emailE = email1 + email2 + '@' + email3 + email4;
    document.write('<a href="mailto:' + emailE + '">' + emailE + '</a>')
    };
    </script>




    2 - In the head section of my page, I entered this:

    <script type="text/javascript" src="emailasp.js"></script>



    3 - Then, where I want the email address to show up, I entered the following:

     <script language="javascript">emailantispam('crog','ers28','gma','il.com');</script>


    What have I done wrong?

    Thanks,
    Claudia

  • Claudia Rogers

    Claudia Rogers

    November 3, 2014 at 17:44 pm

    Help me, please! The email address is not showing up where I tell it to display. These are the steps I took:

    1 - I save the script below in a separate file called emailasp.js

    <script language="javascript">
    function emailantispam(email1, email2, email3, email4){
    emailE = email1 + email2 + '@' + email3 + email4;
    document.write('<a href="mailto:' + emailE + '">' + emailE + '</a>')
    };
    </script>[/js>



    2 - In the head section of my page, I entered this:

    <script type="text/javascript" src="emailasp.js"></script>



    3 - Then, where I want the email address to show up, I entered the following:

     <script language="javascript">emailantispam('crog','ers28','gma','il.com');</script>


    What have I done wrong?

    Thanks,
    Claudia

  • Saleem Khan

    Saleem Khan

    August 3, 2012 at 07:15 am

    Thank you, it really worked.

  • schmitt

    schmitt

    August 4, 2008 at 14:12 pm

    Dear sir,
    I'm buying a lot of script now, but I have tested your forms, but when I send the form data with email as well = mail@hotmail without point and extension, the system not do the message to ask for validate email. could you explain me how to complete my script to do it?

  • manohar

    manohar

    February 14, 2008 at 11:49 am

    Please how i can avoid the spamming in sending emails form and insert query in database.
    I got daily 20 t0 25 and more mails are spamming in mails. and stored in a database.

  • mink

    mink

    January 19, 2008 at 00:39 am

    Try it.

  • alice

    alice

    August 17, 2007 at 01:22 am

    on my contact i added the above but and placed "@" to further confuse spam. on the second java script. but on the site it has both addresses. what do i need to do to change or correct. and i wanted an' info@smartitag.com as well.
    also is my top and bottom java in the right place. thankyou for your assistance

  • Kevin

    Kevin

    February 5, 2007 at 07:32 am

    Total newbie. Where do I put each script reference in the webpage? The function script goes where? Can this script be saved as a separate js file and referenced to it with the secondary script?
    ----------------------
    Veselin: JavaScript function can be in separate file but you need to include the file in the head tag of your web pages. Then on the places where you want email address to appear you can put the function reference.

  • nirz

    nirz

    December 22, 2006 at 02:06 am

    is it possible for you to give a working example of this. I am not sure where the codes go and what is my address is, say, "info@mydomainname.com" as opposed to yahoo.com?
    Thank you.
    --------------------------------
    Veselin Stoilov:
    you can use <br />
    <script language="javascript">emailantispam('in','fo','mydomain','name.com');</script>
    --------------------------------
    nirz: oops! The email address is now showing up at the top left hand side of the contact.html page (where the contact form is). Did I put the Javascript line in the wrong place?
    --------------------------------
    Veselin: most probably YES :) it needs to be where you want the email to appear

Add your comment

Captcha
    • PHP Scripts

      Check our extensive collection of top-notch PHP Scripts that will enhance your website!

      Commercial PHP scripts
    • Free Scripts

      Add great new functionalities to your website with our Free Scripts collection.

      Free scripts