Actions

Difference between revisions of "How to cloak email addresses"

From Joomla! Documentation

Line 51: Line 51:
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Tips and tricks 2.5]]
 
[[Category:Tips and tricks 2.5]]
 +
[[Category:Tips and tricks]]

Revision as of 16:58, 27 May 2013

Contents

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:

Clickable link to email address

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.

echo JHtml::_('email.cloak', 'demo@example.com');

Which will display

demo@example.com

Non-clickable email address

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', 'demo@example.com', 0);

This will simply display

demo@example.com.

Display different email address than the hyperlinked email address

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', 'website_catchall@example.com', 1, 'demo@exmaple.com');

This will display something like

demo@example.com

but the actual email hyperlink going to

mailto:website_catchall@example.com

and obfuscated by JavaScript.

Display phrase, hyperlinked to email address

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', 'demo@exmaple.com', 1, 'click here to email me', 0);

This will display something like

click here to email me

but the actual email hyperlink going to

mailto:website_catchall@example.com

and obfuscated by JavaScript.