Creates a mailto link tag to the specified email_address,
which is also used as the name of the link unless name is
specified. Additional HTML attributes for the
link can be passed in html_options.
mail_to has several methods for customizing the email itself
by passing special keys to html_options.
Options
-
:subject- Preset the subject line of the email. -
:body- Preset the body of the email. -
:cc- Carbon Copy additional recipients on the email. -
:bcc- Blind Carbon Copy additional recipients on the email.
Obfuscation
Prior to Rails 4.0, mail_to provided options for encoding the
address in order to hinder email harvesters. To take advantage of these
options, install the actionview-encoded_mail_to gem.
Examples
mail_to "me@domain.com"
# => <a href="mailto:me@domain.com">me@domain.com</a>
mail_to "me@domain.com", "My email"
# => <a href="mailto:me@domain.com">My email</a>
mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
subject: "This is an example email"
# => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
You can use a block as well if your link target is hard to fit into the name parameter. ERB example:
<%= mail_to "me@domain.com" do %>
<strong>Email me:</strong> <span>me@domain.com</span>
<% end %>
# => <a href="mailto:me@domain.com">
<strong>Email me:</strong> <span>me@domain.com</span>
</a>
Please login to continue.