2

以下不起作用

subject = "The amount of £#{@amount} has been sent to your account".html_safe
mail(:to => @email, :subject => subject, :reply_to => 'support@xyz.com')

也没有

subject = "The amount of £#{@amount} has been sent to your account".html_safe

如何在电子邮件主题中显示井号?

4

1 回答 1

3

电子邮件主题(如电子邮件中的所有标题)不接受网页上使用的 HTML 实体。相反,它们对非 ASCII 数据使用了几种不同的编码,所有这些都应该由mailgem 自动应用。

因此,将字符直接放入主题变量中可能最简单,而无需您自己应用任何额外的编码:

subject = "The amount of £#{@amount} has been sent to your account"
mail(:to => @email, :subject => subject, :reply_to => 'support@xyz.com')

请注意,除非您使用 Ruby 2.0(默认为 utf-8 源编码 iirc),否则您可能必须在源文件顶部放置一个魔术编码注释,以便 ruby​​ 将您的源代码解释为类似于此的 UTF-8

# encoding: UTF-8
于 2013-09-09T15:22:44.710 回答