How to cloak email addresses

From Joomla! Documentation

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[edit]

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[edit]

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 the following output:

demo@example.com

Display different email address than the hyperlinked email address[edit]

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[edit]

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.