Re: Line breaks are not displayed in emails

Anonymous
Not applicable

Line breaks are not displayed in emails

Hi,

I am trying to set up a support form with input fields and a textarea where our customers can submit there problems.

After the customer submits the form, our support team gets an email with all the form fields. Easy so far.

Now I have the problem, that line breaks within the textarea are not interpreted as such in the email.

The text from the textarea is one big paragraph in the email.

Any ideas how the line breaks can be displayed?

Thanks for your help!

Tags (2)
17 REPLIES 17
Josh_Hill13
Level 10 - Champion Alumni

Re: Line breaks are not displayed in emails

Do a search for that. I believe someone fixed this somewhere.

But it may not be fixable easily.

Also, i'd suggest using SFDC Cases or an actual support tracking tool instead.

SanfordWhiteman
Level 10 - Community Moderator

Re: Line breaks are not displayed in emails

Florian, to be clear, there isn't a bug here, because the way newlines are entered into textareas is supposed to be different (by design) from the way you force newlines in HTML. Or maybe to put it another way, the text in a textbox isn't HTML, so you naturally have to change it if it's going in an HTML email.

Anyway, the solution is to just trap the text in the form's onSubmit and use one of the methods outlined here: javascript - How do I replace all line breaks in a string with <br /> tags? - Stack Overflow

Note you will be permanently altering the field this way. I expect that's not a problem for your case.

Anonymous
Not applicable

Re: Line breaks are not displayed in emails

Thank you for you help!

This seems to me to be the best way to do it.

SanfordWhiteman
Level 10 - Community Moderator

Re: Line breaks are not displayed in emails

Demo here BTW.

Anonymous
Not applicable

Re: Line breaks are not displayed in emails

Thanks for that!

Anonymous
Not applicable

Re: Line breaks are not displayed in emails

I tried to implement your suggested solution in my setup. And this becomes not that easy since we are using Marketo forms inside Marketo landing pages which is placed in a iFrame.

In this way I am not able to access the form by javascript because it is loaded differently.

Any ideas?

Anonymous
Not applicable

Re: Line breaks are not displayed in emails

I never used email scripting before, but this token really did the trick.

Since I want the line breaks to be displayed in an email, I used the following code as a email scripting token:

$lead.temporaryNotes.replaceAll("\n", "<br />")

Very simple. Never thought about it before.

SanfordWhiteman
Level 10 - Community Moderator

Re: Line breaks are not displayed in emails

Email scripting will work, too, but of course that doesn't fix up the display for a LP (i.e. including the field as a token).

Tyron_Pretorius
Level 9 - Champion

Re: Line breaks are not displayed in emails

For anyone looking at this post now the replaceAll method did not work for me. However, the replace method already replaces all matches

 

$lead.aIEmailBody.replace("\n", "<br /><br />")

 

Here is a useful piece of code that people can copy that sets a fallback if the field is empty or contains NA

 

#if (!$lead.aIEmailBody.isEmpty() && $lead.aIEmailBody != "NA")
    #set( $b = $lead.aIEmailBody.replace("\n", "<br /><br />"))
#else
    #set( $b = "The people have spoken: We’re named Leader in the most recent G2 report.")
#end
${b}

 

Tyron Pretorius