diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb
index c48d27c909..076d5195c9 100644
--- a/actionview/lib/action_view/helpers/url_helper.rb
+++ b/actionview/lib/action_view/helpers/url_helper.rb
@@ -468,9 +468,9 @@ module ActionView
# mail_to "me@domain.com", "My email"
# # => My email
#
- # mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
+ # mail_to "me@domain.com", cc: "ccaddress@domain.com",
# subject: "This is an example email"
- # # => My email
+ # # => me@domain.com
#
# You can use a block as well if your link target is hard to fit into the name parameter. ERB example:
#
@@ -481,7 +481,7 @@ module ActionView
# Email me: me@domain.com
#
def mail_to(email_address, name = nil, html_options = {}, &block)
- html_options, name = name, nil if block_given?
+ html_options, name = name, nil if name.is_a?(Hash)
html_options = (html_options || {}).stringify_keys
extras = %w{ cc bcc body subject reply_to }.map! { |item|
diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb
index 8e0219c883..b37c64afa4 100644
--- a/actionview/test/template/url_helper_test.rb
+++ b/actionview/test/template/url_helper_test.rb
@@ -705,6 +705,11 @@ class UrlHelperTest < ActiveSupport::TestCase
mail_to("me@example.com", "My email", cc: "ccaddress@example.com", bcc: "bccaddress@example.com", subject: "This is an example email", body: "This is the body of the message.", reply_to: "foo@bar.com")
)
+ assert_dom_equal(
+ %{me@example.com},
+ mail_to("me@example.com", cc: "ccaddress@example.com", bcc: "bccaddress@example.com", subject: "This is an example email", body: "This is the body of the message.", reply_to: "foo@bar.com")
+ )
+
assert_dom_equal(
%{My email},
mail_to("me@example.com", "My email", cc: "", bcc: "", subject: "This is an example email", body: "This is the body of the message.")