且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Google Apps脚本中,如何保存用户输入的换行符?

更新时间:2023-09-29 16:06:16

您正在发送html电子邮件,因此您需要用换行符< BR>替换新的行字符'\ n'.

You are sending a html email so you need to replace new line characters '\n' with line breaks <BR>.

这是选项

//Send as text email
MailApp.sendEmail('someemail@somedomain.com',  
                   'This is a subject', 
                   'Here is the text that was entered: \n' + user_input);

//send as html email
MailApp.sendEmail('someemail@somedomain.com',  
                   'This is a subject', 
                   '', {htmlBody: 'Here is the text that was entered: <br>' + user_input.replace(/\n/g, '<br>')});

我尚未测试代码.它可能有语法错误或错字.

I have not tested the code. It may have syntax error or typo.