Difference between revisions of "How to cloak email addresses"

From Joomla! Documentation

m
Line 7: Line 7:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Which will display [mailto:demo@example.com demo@exmaple.com]
+
Which will display [mailto:demo@example.com demo@example.com]
  
 
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.
 
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.

Revision as of 15:21, 10 November 2011

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

Which will display demo@example.com

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

This will simply display demo@example.com.

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

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