2

The following does not work

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

Neither does

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

How can I show the pound sign in the email subject?

32423hjh32423
  • 3,048
  • 7
  • 44
  • 59

1 Answers1

3

Email subjects (as all headers in an email) do not accept HTML entities as used on a web page. Instead, they use several different encodings on non-ASCII data, all of which should be automatically applied by the mail gem.

As such, it it probably the easiest to just put the character directly into the subject variable without any additional encoding applied by yourself:

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

Note that unless you use Ruby 2.0 (which defaults to utf-8 source encoding iirc), you probably have to put a magic encoding comment on top of your source file in order for ruby to interpret your source code as UTF-8 similar to this

# encoding: UTF-8
Community
  • 1
  • 1
Holger Just
  • 52,918
  • 14
  • 115
  • 123
  • thanks but I get the following error with this approach SyntaxError: /Path/to/mailer.rb:29: invalid multibyte char (US-ASCII) – 32423hjh32423 Sep 09 '13 at 15:25