Skip to content

Instantly share code, notes, and snippets.

@phillypb
Last active December 16, 2018 21:08
Show Gist options
  • Save phillypb/990d50459685eabcf4d77c650eeab9b4 to your computer and use it in GitHub Desktop.
Save phillypb/990d50459685eabcf4d77c650eeab9b4 to your computer and use it in GitHub Desktop.
function onFormSubmit(e) {
// get spreadsheet info
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dataSheet = ss.getSheetByName('Form responses 4');
// get Form data
var formValues = e.namedValues; // allows row Headers to be specified when looking-up values
var theRow = e.range.getRow(); // this is the row the Form data is written to
var name = formValues['Name'];
var username = formValues['Username'];
var bookTitle = formValues['TItle of the returned book'];
var receipt = formValues['Receipt'];
// ************ START OF EDIT EMAIL SECTION ************
// edit text within single quotes below to change email subject
var subject = 'Automatic message from the Refund form';
// edit text within single quotes below to change email body
var body = 'This is an automatic message generated by the Refund form.' + " \n\n";
body+= 'Information provided\n------------------------------------------- \n';
body+= 'The persons name is: ' + name + " \n";
body+= 'The persons course is: ' + username + " \n";
body+= 'Title of the returned book: ' + bookTitle + " \n";
body+= 'Link to receipt: ' + receipt + " \n";
Logger.log(body);
// edit any options for email below
var options = {noReply:true};
// send email
MailApp.sendEmail('mail@example.com', subject, body, options);
// ************ END OF EDIT EMAIL SECTION **************
// writes 'Email sent' into alert column
var alertCell = dataSheet.getRange(theRow, 7);
alertCell.setValue('Email sent');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment