Google Forms - Email Notification Script - Send Confirmation Emails to Users

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right in this video I'm gonna show you how to send a confirmation email after somebody fills up your Google Form I have this very simple form here see it's asking for email name zip code it doesn't matter what's in the form and all that information goes to this spreadsheet so really the only thing here in this form we want to do we want to make sure that we're actually gathering email address so the way you do that you go to your settings which is this gear icon all the way on top right here I'm gonna open that and you want to make sure this collect email addresses is checked that's pretty much all we have to do in the form the rest of the form it doesn't matter you can do your own form or whatever fields you have are fine so with this what we're going to do we're going to basically create a script that's going to send an email every time somebody fills up this form and send that email to the person that actually fills out the form so whatever email is typed here in this email address that's where it's gonna be sent now to do this we're gonna have to use Apps Script events so here's our events documentation so there are different events depending on what Google application you use so if we use Google sheets it has its own events for example we have open spreadsheet event change event edit event Google sheets also have form submit event which we can actually use to do what we're about to do but that's not what I'm gonna use today so I'm gonna keep scrolling down Google Docs until I find Google Forms there it is Google Forms events that's what I'm looking for so in events for Google Forms we have open and we have formed submit and that's what we're going to use on our Google Forms to actually send our confirmation emails so I'm gonna go back to my form I'm gonna click on this little more icon right here and I'm gonna look for script editor I'm gonna open the script redditor should look like this I'm gonna create a function here whatever function here is fine I'm just gonna rename this to make this a little prettier I'm gonna call this send email it's good you can call it whatever you want that's the function and this function we're gonna write the script to actually make that happen now this is gonna be an event that's gonna be triggered this function is gonna be triggered by that event when somebody feels up the form and that is going to accept event object here so I'm gonna call that e now let's try to go and look at that documentation so see that's gonna be this event thing and that's gonna have these things in this object so we're gonna have the response we're gonna have the source and we're gonna have the ID so that event is gonna have this response in it which is going to be this object which is a form response so I'm gonna just copy that response let's get that in mind so if we look inside of that response if I go back here that's gonna be a form response I'm gonna open this it's gonna have its own methods see it's gonna have get ID get item responses and one of those methods is get respondent email so that should give us a string email so let's also just copy that so we have this too so that's a method that will give us the email and that email is basically gonna be whatever was typed in in this email box now to do this whole thing we're gonna use a few different things so we need to use HTML service to create an HTML email we're gonna have to use Gmail app to be sending emails and then finally we're gonna use the actual object that's gonna be basically sending this information from this form so let's get started by creating that e so I'm gonna go on their file new create an HTML file that's gonna be our HTML email I'm gonna call this email hit OK that's gonna be our HTML email so here I'm gonna do the actual HTML for our email it can be whatever you want I'm just gonna keep this as simple as possible I'm gonna make a paragraph here like this in here we're gonna make a paragraph we're gonna say thanks for feeling out the form and then we'll do another paragraph here and that will be something like best regards we'll do a break and I'll send this to any lines just to make this look nice I guess that's regards our team you can write your own HTML this doesn't matter whole point is this is going to be our HTML email you can create it any way you like I'm gonna save this this is called email HTML that's the name of the file now I'm gonna go back to my code I need to create that HTML out of this so to do this we're gonna use HTML service so I'm gonna create for HTML equals 2 we're gonna use HTML serve this dot and here we're gonna do create template from file and the file name is this file right here email HTML so that's gonna be email dot HTML that's the file I guess we're gonna leave it at that and then I'm gonna create another variable I'm gonna call it HTML text to create that text I'm gonna take my HTML and do this method called get code which should get us string HTML so that's that some : to end the line so this HTML text should be the text HTML version of whatever HTML we have here in this HTML file now that we have this we should be able to send an email using Gmail app using that HTML text so let's try to use that so Gmail app dot so in this gmail app you have this method called send email and the send email has a few different ways of using it one of them is this so we need to provide who we're sending this to so for now I'm gonna create some variables here which we're going to use later on so I'm gonna say var email too and we'll just leave this empty for now so later on will populate it with the email for the person who will be getting that email that's gonna be this the subject so let's create a variable for that subject and that's gonna be thanks that's the subject line for the email thanks for participating something like that and that's gonna be the subject line that's gonna go here we already have that now the other two I'm gonna have to take a look really quickly here to see this so this is our Gmail app documentation and email that's that it says so we have this subject body and options advanced parameters so there it is HTML body is one of the parameters here so that's what we're going to use to send the actual email because we're trying to send an HTML email here I wonder if we still have to set the body let's see attachment example please while and then we have all of this stuff okay that kind of makes sense that means the body so we'll save our text body and that will be let me do this that will be this email requires HTML support please make sure you open with a client that supports edge so it doesn't matter it's just a message when HTML support is turned off it could also be a text version I guess of your email but that's what I'm gonna do there text body and that's gonna go here so text body finally we need to set these options so since this is called options here I'll create a variable options and that's an object and that object is gonna have this property HTML body which should be the actual HTML body which will be our HTML text right here because I believe it said HTML body here should be string yep good so this will be the body this will be the text body when it doesn't support HTML and then finally we'll have this thanks for participating which the subject line is so the only thing we now need to do is provide an appropriate email address and that email is supposed to come from here so to get that we need to remember we're gonna use this this e we're gonna get the response we get to get email address so email to I'm gonna take that e in that e we're gonna have this response that response we should have this method get respondent email based on our documentation now before we actually go ahead and send our email maybe we should make sure that that email exists so we're gonna say if that email - is not undefined then we'll send the email save this I think that should do it now to make sure that I give all the permissions here that are necessary I'm gonna have to run this function now when I run that function it's not gonna have all that you know the respondent get emailed all of that is not gonna be available because we're not submitting the form but that's fine we just do this to make sure we give all the permissions for the script so I'm gonna run this see it's gonna ask for permission so I'm gonna open that I'm gonna give all the permissions necessary allow that and see it's now undefined the response because this should be triggered by our event not just manually run this but it doesn't matter we're gonna just dismiss that now with this now I'm gonna go back and try to fill out the forms so let's open the actual form so let's fill this out let's see what we get submit the form and check what happened so I'm gonna go to the same folder of my gmail to see what's going on apparently nothing let's go back oh of course I forgot to set up the whole trigger to run this function yes so I created this function but this function is not gonna know to run until I set it up to run every time somebody actually fills out the form and to get that done this is where we have to set up a trigger so I'm gonna go under this edit another edit menu here there is current projects triggers I'm gonna click on that right now no triggers here as you can see I'm gonna go here on bottom ride add trigger and I want to trigger that function I called it send email if you called it something else you want to make sure that matches then this should be head that's fine we want to trigger this function from the forum and we want to trigger this when somebody submits that forum so I'm gonna switch this to own forum submit if that script fails you can get notifications I'm gonna do wickley that's good enough for me and then just save that should set up the trigger to make sure we run that every time we actually do this so apparently I have to do this so again permissions save one more time hopefully that permission stuff worked because I had a blocker and it didn't let that initial screen to pop up right away but otherwise you should get that screen right away and just give permissions so I'm gonna go test this again I'm gonna go back to my form refresh this thing let me fill this out it's a bit go back and check my scent for my gmail there this I have received an email and this is what was sent I'm gonna go check what it looks like and do we have some problems here so that created that whole JavaScript function instead of doing the actual HTML itself but email was sent that was the good part our HTML didn't work properly so we're gonna have to go back and fix this I'm gonna go back to my code again so apparently this is where it went wrong getting this code didn't work so we need to fix that I'm gonna have to troubleshoot that and see what happened there so I'm gonna do log or log and I'll print out this HTML text save this and just run this so I'll get that error but that's fine I want to take a look at my locks so far so that's what I'm getting out of this that's the problem I shouldn't be getting all of this it should be just my HTML so what I'm gonna try to do I'm gonna try to do evaluate on this HTML and then we'll so get content see that seems like it's gonna give us the string so we're gonna not use this gate code I thought that would generate it documentation looked like it but I was wrong so dismiss this I'm gonna look at the log that's much better that looks like a proper HTML result now so this should work so I'm gonna take this away save this and go back and submit my form one more time so reload this sir met all right let's go take a look our sent emails there is the new one see it's thanks for participating that's the email and we have the proper email generated all of that looks good so yeah that works we can make this more personalized if we wanted to so technically could go and grab all that name and all that information and that use it in our email to to take this to the next level but I'm trying to keep this simple this should send us a confirmation message for the participant and it works and if you wanted to modify your email you can go back to your script open this HTML and just type whatever you need just create your HTML message and that should just work out that should do it for this video thanks for watching please subscribe and I'll see you the next one
Info
Channel: Learn Google Spreadsheets
Views: 87,189
Rating: undefined out of 5
Keywords: Google Forms, Email, Notification, Confirmation, Script, Send, submitted, HTML, Apps Script, Gmail
Id: H7WFkt6J4rs
Channel Id: undefined
Length: 18min 5sec (1085 seconds)
Published: Mon Jun 24 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.