admin管理员组

文章数量:1312662

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.

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.

Share Improve this question edited Feb 24, 2021 at 6:49 Random 3,2361 gold badge17 silver badges25 bronze badges asked Nov 1, 2016 at 0:45 JaitniumJaitnium 6503 gold badges16 silver badges28 bronze badges 4
  • it'd be %0D%0A not %0D%A ... and it's <br/> not <\br> ... my guess, go with <br/> – Jaromanda X Commented Nov 1, 2016 at 0:50
  • @JaromandaX, thanks for catching that... I meant %0D%0A. I added the forwardslash to <\br> because it keeps evaluating to a linebreak. – Jaitnium Commented Nov 1, 2016 at 1:00
  • 1 and what of <br/> – Jaromanda X Commented Nov 1, 2016 at 1:00
  • I think it depends on your content. is your content in plain text or html? I can not see much detail info in the documentation on that site. – EhsanT Commented Nov 1, 2016 at 3:28
Add a ment  | 

2 Answers 2

Reset to default 10

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...

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.

本文标签: javascriptI39m unable to add newlines to the email39s contentStack Overflow