MailTo is a Radiant CMS extension that hides e-mails from robots. It is a wrapper for the Rails mail_to method and supports all of the same options provided by that method.
The mail_to
tag obfuscates an email address as a block of javascript. For example,
<r:mail_to email="[email protected]" encode="hex" />
is turned into
<a href="mailto:%6a%6f%65@%65%78%61%6d%70%6c%65.%63%6f%6d">[email protected]</a>
and will be displayed as a human-readable link.
Install the extension at vendor/extensions
. Make sure the extension's directory is named mail_to so that it will load properly.
Use the tag in pages or snippets like this:
<r:mail_to email="[email protected]" replace_at="_at_" replace_dot="_dot_" class="email" />
This tag will be used by the textile editor extension. It also generate a mailto:
encoded link:
<r:enkode_mailto email="[email protected]" link_text="Joe User" />
is turned into
<a href="mailto:%6a%6f%65@%65%78%61%6d%70%6c%65.%63%6f%6d">Joe User</a>
Both email and link text are automatically hex encoded. This tag takes no other options.
From the Rails documentation:
Creates a mailto link tag to the specified
email_address
, which is also used as the name of the link unlessname
is specified. Additional HTML attributes for the link can be passed inhtml_options
.
mail_to
has several methods for hindering email harvesters and customizing the email itself by passing special keys tohtml_options
.Options
:encode
- This key will accept the strings "javascript" or "hex". Passing "javascript" will dynamically create and encode themailto:
link then eval it into the DOM of the page. This method will not show the link on the page if the user has JavaScript disabled. Passing "hex" will hex encode theemail_address
before outputting themailto:
link.:replace_at
- When the link name isn‘t provided, theemail_address
is used for the link label. You can use this option to obfuscate theemail_address
by substituting the @ sign with the string given as the value.:replace_dot
- When the link name isn‘t provided, theemail_address
is used for the link label. You can use this option to obfuscate the email_address by substituting the . in the email with the string given as the value.:subject
- Preset the subject line of the email.:body
- Preset the body of the email.:cc
- Carbon Copy addition recipients on the email.:bcc
- Blind Carbon Copy additional recipients on the email.
<r:mail_to email="[email protected]" /><br/>
# => <a href="mailto:[email protected]">[email protected]</a>
<r:mail_to email="[email protected]" name="My email" encode="javascript" /><br/>
# => <script type="text/javascript">eval(unescape('%64%6f%63...%6d%65%6e'))</script>
<r:mail_to email="[email protected]" encode="hex" encode_name="true" /><br/>
# => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">me...om</a>
<r:mail_to email="[email protected]" replace_at="_at_" replace_dot="_dot_" class="email" /><br/>
# => <a href="mailto:[email protected]" class="email">me_at_domain_dot_com</a>
<r:mail_to email="[email protected]" name="My email" cc="[email protected]" subject="This is an example email" /><br/>
# => <a href="mailto:[email protected][email protected]&subject=This%20is%20an%20example%20email">My email</a>