I am totally new to coding and I need some help on a bit of code. Here is my problem: I want to take many cells of data in a Google spreadsheet and send it in an email. I figured out how to pull the data into an email and the email sends, however, the data is only separated by commas and it is hard to distinguish. How can I make each cell's data appear on a separate line in the email? I believe I can do this with arrays, but as I said, I am new to this and I cannot figure out how to do it with what I have read so far. If you could provide an explanation, that would be greatly appreciated as well - this will, hopefully, keep me from asking the same question again and teach me. Thank you for your patience and help!
function emailData() {
//Gather data from "Responses" sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var responses = ss.getSheetByName("Form Responses");
var lastRow = responses.getLastRow();
var data = responses.getRange("A"+(lastRow)+":AK"+(lastRow));
var values = data.getValues();
//Gather email addresses from "Email" sheet (I have not gotten this far yet)
var email = ss.getSheetByName("Email");
var startRow = 2;
var emailAdress = "email@email.com";
var subject = "Capacity Campaign Contact Form";
MailApp.sendEmail(emailAdress,subject,values);
}
As you can see, I am missing a tr opening tag before "Business or Church". However, my code appears to be exactly like yours. You can see what it is doing in the screen shot.
Your array (called Values) is a 2 dimension array corresponding to a row in your sheet, it means that you have to iterate through its first element. I wrote a small script with a function that composes the message with headers and values like this :
note that you could use the same structure to build an even better looking email in html format using a html table (see reference here)
EDIT2
I wrote a little piece of code that generates both in text and HTML in a table, feel free to improve HTML formating with colors etc...
EDIT 3
following your comment : here is the log of my test sheet + screen capture. Check your log to see if you get a similar structure with your data.
Each of these tags must be terminated by a /t... closing tag (with surrounding <>)to be valid. The loop structure in the script takes care of that automatically as you can see in the log data.
Note also that I added a table end tag at the end of the loop... I forgot it in my first code but it worked like that in my tests.