Skip to content

Instantly share code, notes, and snippets.

@cms-jakes
Last active May 27, 2018 15:41
Show Gist options
  • Select an option

  • Save cms-jakes/0a7d61926626393246eb4a107c1d7488 to your computer and use it in GitHub Desktop.

Select an option

Save cms-jakes/0a7d61926626393246eb4a107c1d7488 to your computer and use it in GitHub Desktop.
///////////////////////////////////////////////////////
// Google Form Email Script
// Author: Jacob Standish ([email protected])
// This script sends an email to a person or group every time the form is submitted
// The body of the message contains the responses from the form styled with the form questions as HEADING2 and responses as Paragraphs.
// This script needs to be installed into a Google Form (not the spreadsheet) with the On Form Submit trigger set
///////////////////////////////////////////////////////
var recipients = "[email protected]"; //replace with the address you want to receive the email
function onFormSubmit(e) {
var email = e.response.getRespondentEmail();
//Trim username to first and last.
var name = email.replace(/\@.+/g,"");
var fname = name.replace(/\..+/g,"");
var lname = name.replace(/.+\./g,"");
var domain = email.replace(/.+\@/g,"");
//Logger.log(name+" ;"+fname+" ;"+lname+" ;"+ domain)
var items = new Array();
var response = new Array();
//Process response into components.
var e_response = e.response.getItemResponses();
for (i=0;i<e_response.length;++i){
response.push(e_response[i].getResponse());
items.push(e_response[i].getItem().getTitle());
}
var message = "<h2>Submitted by "+email+"</h2><hr/>";
for(j=0;j<response.length;++j){
var message = message + "<h2>"+items[j]+"</h2><p>"+response[j]+"</p><hr/>"
}
Logger.log(message);
//Send email with information
var logoURL = ""; //url of logo if you want one to display in the body of the message
var logoBlob = UrlFetchApp
.fetch(logoURL)
.getBlob()
.setName("logoBlob");
MailApp.sendEmail({
to: recipients,
subject: "Google Form Report",
htmlBody: "<img src='cid:logo' width='40%'><br/><h1>Heading Title</h1>"+message,
inlineImages:
{
logo: logoBlob
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment