9

I'm sending a plain text email and was wondering how I add a line break to this. It's showing up on on the same line.

From: <%= @name %>
<%= @text %>

Thanks

adamwstl
  • 338
  • 3
  • 12

4 Answers4

16
<%= "\r\n" %>

In double quotes and inside '<% %>'.

Otherwise it's considered as simple text.

Sergii Mostovyi
  • 1,361
  • 1
  • 15
  • 19
12
\r\n

or if you're sending html email:

<br />

so:

From: <%= @name %> \r\n <%= @text %>
From: <%= @name %> <br /> <%= @text %>
Jimmy
  • 9,686
  • 14
  • 59
  • 78
  • 4
    This may work on some systems but is not technically correct. New lines in plain text emails should always be CRLF ("\r\n"): [RFC 2822](http://www.faqs.org/rfcs/rfc2822.html) – Chris Williams Mar 15 '11 at 18:05
  • This isn't working for me. At least not in the Rails 4.1 mailer preview (I haven't viewed a sent email). I'm using Haml and have `\r\n` on its own line. [Renders like this.](http://i.imgur.com/uCbtB2t.png) – Dennis Jun 06 '14 at 21:18
  • 5
    \r\n should be inside <%= %> and in double quotes - <%= "\r\n" %>. Otherwise it's considered as simple text – Sergii Mostovyi Nov 10 '14 at 07:57
  • And if you're using HAML and @SergiiMostovyi's suggestion, use #{'\r\n'} – user1515295 Sep 27 '17 at 13:28
2

I could be completely wrong, but isn't it a simple \n ?

Christina Mayers
  • 516
  • 5
  • 11
  • 1
    I'm seeing the literal \n characters in my emails (with no line breaks at all). It looks like they were converted from line breaks to \n – quantumpotato May 12 '13 at 02:35
0

If your template is in HAML, some_template.text.haml, you can use the \ char:

= t(".salutation_start", name: name)
\
= t(".paragraph.text")
\
\
= t('.salutation_end')
\
= t('.contacts')
Rui Nunes
  • 798
  • 1
  • 8
  • 15