1
votes

We are using a Google Spreadsheet script to send us reformatted email.

Problem: We are wondering if there is a way to retain minimal formatting such as line breaks for the "strEnquirerMessage" cell for the following script.

I have tried including htmlBody somehow but no luck so far. Any help is greatly appreciated. Thank you.

User emails this message in contact form:

Line 1

Line 2

Line 3

We currently receive this in the email from this script: Line 1 Line 2 Line 3

Goal is to receive this:

Line 1

Line 2

Line 3

   var strEnquirerName = values[row][1];
   var strEnquirerEmail = values[row][2];
   var strEnquirerAddress = values[row][3];
   var strTopic = values[row][4];
   var strEnquirerProducts = values[row][5];
   var strEnquirerMessage = values[row][6];
   var strMessageBody = "<b>NAME:</b> " + strEnquirerName + 
     "<br/><br/><b>EMAIL:</b> " + strEnquirerEmail + 
     "<br/><br/><b>ADDRESS:</b> " + strEnquirerAddress + 
     "<br/><br/><b>TOPIC:</b> " + strTopic + 
     "<br/><br/><b>PRODUCTS:</b> " + strEnquirerProducts + 
     "<br/><br/><b>MESSAGE:</b> " + strEnquirerMessage; 
   MailApp.sendEmail("[email protected]", strEnquirerEmail, " Contact form from " + strEnquirerName + " - " + strEnquirerEmail + " Re: " + strTopic, strMessageBody);
1

1 Answers

1
votes

Thanks to this post, I have found the answer. Below is the updated line from the above code:

   var strEnquirerMessage = values[row][6].replace(/\n/g, '<br>');

Beside the cell value is code to replace Google Spreadsheet's new line character with a line break. Hope this helps others.