when you're sending an email with a string that includes line breaks or newlines entered by a user, you might encounter an issue where the line breaks are lost when rendering the email body in HTML format. This is because HTML doesn't recognize plain newline characters (\n
or \r\n
) as line breaks by default.
To ensure that user-entered line breaks appear correctly in the email body, you can convert the newline characters to HTML-compatible <br>
tags or wrap the text in a <pre>
tag, which preserves formatting.
<br>
: Use the String Replace
action in Mendix to convert \n
to <br>
.<pre>
tag: Wrap the user input in a <pre>
tag to preserve the formatting.Hi Clara,
What if you let the user input be in Rich text instead of the text area widget. Then the output will also in HTML and thus be fine to be used in the Email body.
Be sure that you sanitize the user input as that is a security best practice.
Good luck,
Jurre
Thank you all for the suggestions!
All of the solutions are working for me, but from what I tried, I finally preferred to use the replaceAll string function because, from my point of view, it was the easiest way to keep everything else looking the same.
The rich text worked great but modified the look of my page a bit, and the <pre>
tag for HTML was showing a different font than the standard one that HTML shows in a Mendix email. So, I found it faster to use the replaceAll function.