javascript 文本变量中的新行

new line in javascript text variable

我这里有这段文字:

var text1 = '<p>Hey ' + rows[i].NAME + ', \n\nFrom our team here at Indera Technologies ...

我通过nodemailer transporter中的html参数这样发送:

 var text1 = '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body><p>Hey ' + rows[i].NAME + ', \n\nFrom our team here at Pier Solutions, we wanted to let you know that we have done a little re-branding. We have changed our name to... drum roll please! \n\nIndera Technologies!</p>'
                    
var text2 = '</body></html>'
                    
// send mail with defined transport object
                    let sendBatch = await transporter.sendMail({
                        from: "solutionspier@gmail.com", // sender address
                        to: rows[i].EMAIL,
                        // bcc: emails, // list of receivers
                        subject: "It's Official, we've rebranded!", // Subject line
                        html: text1 + req.body.htmlContent + text2
                    });

然后当我发送电子邮件时,它实际上显示在电子邮件中,如下所示:

Hey Gianluca From our team here at Indera Technologies

它只做一行而不是换行。

我该如何解决这个问题?

如果这应该是 HTML 的一部分,请使用 <br> 标签而不是 \n。 或者更好的是,将下方文本放在单独的 <p> 标签中

此外,您可能想了解 Template Literals,这将使编写这样的字符串变得容易得多