Jump to content

Encode email address, but don?t open email client when clicked on?


Recommended Posts

There are quite a few sites that will let you encode your email address via JavaScript to show it on a web site without bots being able to find it, & therefore spam it (or at least it stems the tide).


When you click on them it opens a new email message in the user?s email client with the email address in the ?to? field.


What I want to do is display an email address on a web site & encode it in JavaScript (to help prevent spam), but I don?t want it to open a new email when clicked on (I want to activate some different JavaScript instead).


Does anyone know if this would be possible?

Link to comment
Share on other sites

For those of you wanting a function to 'obfuscate' an email address, here is one sample:

// obfuscate emails function

function hexentities($str) {
   $encoded = '';
   for($i = 0; $i         $encoded .= ''.bin2hex(substr($str, $i, 1)).';';
   return $encoded;


$email = "myself@mydomain.com";
echo hexentities($email)

Displays 'myself@mydomain.com' on the html page as output to the screen/page, but the source code is hex encoded so 'most' Bots won't find the addresses. Never any guarantees in life, and the Bots are getting smarter all the time, too.

See also: http://www.jlhaslip.trap17.com/samples/email/index.php

View source that page and look at the Footer code to see a real example in use.

Edited by jlhaslip
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...