Please excuse me for my lack of understanding of the process of Google apps. I recently figured out how to send email containing data from Google Form submission to myself/others. The script I have is working great, however, I have ran into an issue where the content of the message that the script sends is in a linear format. For example, the user enters two sentences with a line separating them, and all I see is a long linear text.
It would help me greatly if anyone knows how to receive Form submission data in "As-Is" form submitted by the user. Please take a look at my code to see if there is any way to implement such a thing in Google Scripts.
function sendFormByEmail(e) {
var email = "xxxxx@xxxx.com";
var subject1 = "Approval Required Case # ";
var subject2 = " submitted by: ";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message2 = "";
var message1 = "";
var replyemail = "";
for(var i in headers)
message2 += "<u><b>" + headers[i] + "</b></u> : " + e.namedValues[headers[i]].toString() + "<br><br>" + "\n\n";
message1 += "<b><font color ='blue'><big> Hi XXXX, </big></font></b>" + "<br><br>" + "Could you please approve the below? " + "<br><br>";
replyemail = e.namedValues['Username'].toString();
Logger.log(message);
subject=subject1 + e.namedValues['Case Number'].toString() + subject2 + e.namedValues['Username'].toString();
var message = message1 + message2;
MailApp.sendEmail(email, subject,message,{name: "Approval Submission: Review",replyTo: replyemail, cc: "" ,'htmlBody':message,});
}
Again, Thanks in advance.
You can use the JavaScript replace method to change all the newline characters with <br>
message = message.replace("\n", "<br>");
MailApp.sendEmail(email, subject,message,{name: "Approval Submission: Review",replyTo: replyemail, cc: "" ,'htmlBody':message});
For: Anybody interested..
I figured out how to achieve the desired effect stated in my original question. How..?
Very simple addition: .replace(new RegExp('\\r?\\n','g','<br /v>')
after my content string.
Check out the code below
message2 += "<u><b>" + headers[i] + "</b></u> : " + e.namedValues[headers[i]].toString().replace(new RegExp('\r?\n','g'), '<br />')
+ "<br><br>" + "\n\n";
Best of luck to all!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.