Using Google Script for your Email autoresponders

Google Autoresponder Script

When you create a Google form the responses will be stored in Google Sheets which acts as the database. Go to the Sheet by clicking one the form responses. When you are in the sheet go to the tools menu and select "script editor".

Using Google Script Editor

You need to create a new project. Call it "Google Form Autoresponder" or whatever you want. Doesn't really matter. Now you need to copy and paste the following code. Edit the code according to your own variables.

/* Send Confirmation Email with Google Forms */
function Initialize() {

var triggers = ScriptApp.getProjectTriggers();

for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}

ScriptApp.newTrigger("SendConfirmationMail")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();

}

function SendConfirmationMail(e) {

try {

var ss, cc, sendername, subject, columns;
var message, value, textbody, sender;

// Enable variables such client name and subject to be placed in body and subject.
// This will depend on your form.

var clientname = e.namedValues["Name"].toString();
var tutorsubject = e.namedValues["Subject/s"].toString();

// This is your email address and you will be in the CC
cc = "yourname@yourdomain.com";

// This will show up as the sender's name
sendername = "Your Name";

// Optional but change the following variable
// to have a custom subject for Google Docs emails
// to have a variable in subject you would use the following code
// subject = tutorsubject + " tuition enquiry";
subject = "Tuition Enquiry";

// This is the body of the auto-reply
message = "Hi " + clientname + ",<br><br>Further to your enquiry about our tuition services. I have allocated you a tutor coordinator who will be in touch shortly. <br><br>Information about our rates can be found <a href=http://google.com>here</a>. <br> <br> If you have any queries please let me know. <br><br>Kind Regards, <br>Your Name<br>Title<br>www.google.com <br>Phone Number<br><br>";

// This code places the respondents details in the email in case they want to check their submission.
ss = SpreadsheetApp.getActiveSheet();
columns = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];

// This is the submitter's email address
// Make sure you have field called Email Address in the Google Form
sender = e.namedValues["Email Address"].toString();

// Only include form values that are not blank
for (var keys in columns) {
var key = columns[keys];
var val = e.namedValues[key] ? e.namedValues[key].toString() : "";
if (val !== "") {
message += key + ' :: ' + val + "<br />";
}
}

textbody = message.replace("<br>", "\n");

GmailApp.sendEmail(sender, subject, textbody, {
cc: cc,
name: sendername,
htmlBody: message
});

} catch (e) {
Logger.log(e.toString());
}
// FOR ASSISTANCE WITH GOOGLE SCRIPT AND OTHER GOOGLE QUERIES GO TO GOOGLENESS.COM
}

Once you've copied the code. Click save. From the program drop down menu click "start". Now click "run" which will run the start program. Google will ask you to authorize the program. You need to give permission for the program as the autoresponder will be sent from your gmail account.

You can make changes to the autoresponder as you wish. For more help you can contact me.

Comments

comments