How to cloak email addresses

From Joomla! Documentation

Revision as of 15:21, 10 November 2011 by Manhim (Talk | contribs)

It is good practice to make sure that email addresses that appear on your website are obfuscated, or 'cloaked'. This means that they are readable by people, but not by bots that harvest email addresses from websites for spamming purposes. Email addresses are made un-readable to these bots by 'assembling' them via JavaScript when the page is loaded. Although they appear on your screen as a readable e-mail address, the actual email address itself never appears in the code.

Joomla has inbuilt email cloaking functionality that can be called within a component or module template, through the JHtml Class. To call this cloaking routine in your component, use the following syntax:

echo JHtml::_('email.cloak', '');

Which will display

This will create a mailto link, that people can click on to email that email address, that will be hidden from bots in complicated javascript.

If you want to not have a mailto link, and just have an email address displayed that is not a hyper link, use the following syntax:

echo JHtml::_('email.cloak', '', 0);

This will simply display

If you would like to have a different email address displayed from the one that is actually linked to, you use the following syntax:

echo JHtml::_('email.cloak', '', 1, '');

This will display something like but obfuscated by JavaScript.

And if you would like a different phrase other than an email address displayed as a mailto hyper-link, use this syntax:

echo JHtml::_('email.cloak', '', 1, 'click here to email me', 0);

This will display something like click here to email me but again obfuscated by JavaScript.