Jaitnium
Jaitnium

Reputation: 650

I'm unable to add newlines to the email's content

I'm using EmailJS to successfully send emails, but I can't add newlines to the content of the email.

Info about Email.JS can be found here

This is what the calls looks like:

emailjs.send("[service]", "[template]", {"send_to": "[email]", "subject": "[subject]", "content": "This is a \nsentence"});

I've tried using %0D%0A, \r\n, \n, and <br/> but each email doesn't have a newline.

Upvotes: 5

Views: 2154

Answers (2)

Purgarcita
Purgarcita

Reputation: 325

It is possible to do it using <br> if the variable in the template is wrap with three brackets {{{content}}}.

3 brackets sintax means that the variable is not espcaped, and it is used when the variable contains HTML code.

Also you can use &nbsp; to add an space etc...

Upvotes: 10

Dave
Dave

Reputation: 13

I solved this issue. EmailJS does not allow the newline character in the send variables because it does not want you to pass in a large string for the entire content of the email. Instead you have to use the email template within EmailJS to organize the content as you want it. You need to create new variables within your template for each piece of dynamic content passed by send and keep the static content in your EmailJS template.

It has to do with their pricing structure. You have to subscribe to get access to more templates. If you could pass in a single string for the email you would not need more templates.

Upvotes: 1

Related Questions