
Google Docs contact form is one of the most popular contact form on the web and a lot of people are not aware that you can also send automatic reply to the contact form messages using some Google API code.
There is a simple way to Send the contact form in the form of email to your inbox described here. However, if you want a automated reply email sent to your customers it needs to be done using some JavaScript function which can be easily configured to be called inside Google Docs. Below are the steps to configure a automated reply email for your contact form.
Below are simple steps to setup the auto reply email.
There is a simple way to Send the contact form in the form of email to your inbox described here. However, if you want a automated reply email sent to your customers it needs to be done using some JavaScript function which can be easily configured to be called inside Google Docs. Below are the steps to configure a automated reply email for your contact form.
Why Send Auto Reply
The default Google contact form feature provides a google docs spreadsheet with user responses, and responding to them needs to be done using manual emails. Sometimes its not feasible to reply back to people immediately, I have found some of the main reasons as listed below- In case your site is really popular and lot of people are trying to reach you.
- There may be lot of spam contact messages.
- There may be worldwide customers trying to reach you during odd working hours/weekends.
- You may be on vacation.
- You need some time to do research before you respond.
- Some of the categories need not be attended since your answers can be canned. e.g. you want to thank your customer for providing feedback or some help.
Below are simple steps to setup the auto reply email.
- Create Contact Form
- Add JavaScript Function for Auto Reply Email Below is the JavaScript code which can be used to send automated email reply. This code uses Google MailApp utility to send reply. Follow these steps and copy the below code Tools - Script Editor - Copy Below code into the text editor. - Save.
- Field names are case sensitive. Please make sure the field names are exactly matching in the script. (e.g. Email, Subject)
- Make sure to update the script with your own email address on this line
var myemail = "abc@youmail.com";
- In case you want the auto reply content to be really big make sure you split it into multiple lines (and use Javasctipt append) like below instead of keeping all text in one double quote.
var message = "Thanks for contacting FromDev.com. We will get in touch with you shortly. \n\n-----\n\n"
+ "Another line \n"
+ "Another line";
- Add a Trigger The next steps is to add a trigger to run the script on form submission. The trigger is a simple configuration to tell google docs to listen to specific event and take action on it. We are simply going to create a trigger at the event of form submission and execute our auto reply email script in the action response to that event. Follow these steps
- Tools - Script Editor - Resources - Current Script's Triggers
- Select Function name "sendAutoReply"
- Select "From Spreadsheet"
- Select "On Form Submit"
- Save
- Authorize Script You need to Authorize Script to be run by Google API. The authorization step is really important since Google API will not run the script unless its authorized by the creator. Therefore make sure you are creating the script using the same account which owns the contact form.
- Lets Test our Script I believe in test driven development, and as always try to make sure your setup is working fine. This is really simple, just do the form submission using a email address and see if the auto reply email is received as required.
- Something went wrong? Your script is still not working? There can be following reasons - Please make sure you have the exact same field names in your contact form. (Specially for Email and Subject). Checkout our contact form. - If someone enters a invalid email address or other error happens on your form, you would be notified with a email similar to below snapshot.
In case you have not created the contact form before, don't worry. Its really easy and free. Checkout this simple Youtube Video about "How To Create Contact Form on Google Docs". This example assumes you have at least four fields in your contact form (Name, Email, Subject and content/message). Checkout our contact form for details.
function sendAutoReply(e)
{
// Remember to replace abc@youmail.com with your own email address
// This will be used to send you a email notification in case of error on form
// for example if someone entered a wrong email address.
var myemail = "abc@youmail.com";
//Leave this field blank - it will be auto populated from "Email" field in
// your contact form. Make sure you have a "Email" Field in your contact form.
var email = "";
// This is going to be the subject of reply email
// You can change it as per your requirements
var subject = "Re: ";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var message = "Thanks for contacting FromDev.com. We will get in touch with you shortly. \n\n-----\n\n";
try {
for(var field in e.namedValues) {
message += field + ' :: '
+ e.namedValues[field].toString() + "\n\n";
if (field == 'Subject') {
subject += e.namedValues[field].toString();
}
if (field == 'Email') {
email = e.namedValues[field].toString();
}
}
// We are using JavaScript MailApp util of Google Apps Script
// that sends the email.
MailApp.sendEmail(email, subject, message, {replyTo:myemail});
} catch(e){
MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission. No reply was sent.", e.message);
}
}
Special Caution
Please make sure you take care of following things when you create a form and update any code in script.
Nice! Thank you, it is very useful.
ReplyDeleteJirka - Thanks for your comment. I am glad to know that it was helpful.
DeleteI have a question, I also want to embed a photo (a guest pass to my facility). I've tried html format by using img src and i've tried to also do my own scripting
Deletewith no result. the best i can do is provide a link to the image? Any thoughts on this? Sorry, I'm new to this whole thing!
Thanks you
DeleteThis comment has been removed by the author.
ReplyDeleteHi,
ReplyDeleteI'm in a bit of a picle.
Is there a way that the email that you receive has the email address of the user in the from field, so that when you hit reply it, it replies to the user and not the Gmail address?
Thanks
I have not tried this however there is a way to set ReplyTo option on mailAPp. Please checkout the MailApp document
DeleteHope this helps.
Try this
DeleteReplace the MailApp.setEmail code with Following code
MailApp.sendEmail(email, subject, message, {replyTo:"youremail@domain.com"});
This is also updated in the post now. Thanks for feedback.
DeleteHi I don't get this - the script emails me which isn't really a 'reply' is it? How do you get it to email the person who filled out the form?
ReplyDeletePlease make sure you have "Email" field in your contact form. This script is going to extract the email field from contact form. If its not provided then email will be sent to you.
DeleteI just updated the script with more clear error handling message. This should also make it more clear for others in future. Thanks for letting me know. Hope this will help you.
DeleteYou have made it very easy for us to understand how to send auto reply on submission of Google docs contact form.
ReplyDeletePharmacy Technician Arizona
This is very helpful. Is there a way to get the email to include a field from a corresponding row in a different sheet?
ReplyDelete@Ben - Thanks for comment. I am glad you found this useful.
DeleteI have not tried manipulating other sheet. What is the scenario you are trying to address? Let me know may be we can think of an alternative.
I got following error ;
ReplyDelete"Cannot read property "namedValues" from undefined."
Please help me out
I have a questions before I can solve your problem.
DeleteHave you created the contact form just like FromDev contact form
Please share you form link with me and I can verify that.
I have to face same message
DeleteHere is my code:
function sendAutoReply(e)
{
// Remember to replace abc@youmail.com with your own email address
// This will be used to send you a email notification in case of error on form
// for example if someone entered a wrong email address.
var myemail = "rauf.ahmed@iiu.edu.pk";
//Leave this field blank - it will be auto populated from "Email" field in
// your contact form. Make sure you have a "Email" Field in your contact form.
var email = "";
// This is going to be the subject of reply email
// You can change it as per your requirements
var subject = "Re: ";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var message = "Thanks for contacting FromDev.com. We will get in touch with you shortly. \n\n-----\n\n";
try {
for(var field in e.namedValues) {
message += field + ' :: '
+ e.namedValues[field].toString() + "\n\n";
if (field == 'Subject') {
subject += e.namedValues[field].toString();
}
if (field == 'Email') {
email = e.namedValues[field].toString();
}
}
// We are using Java MailApp util of Google Apps Script
// that sends the email.
MailApp.sendEmail(email, subject, message, {replyTo:myemail});
} catch(e){
MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission. No reply was sent.", e.message);
}
}
Here is the form:
https://docs.google.com/a/iiu.edu.pk/spreadsheet/viewform?formkey=dG52ZlRjWG5iLTZhTkk0bzZhS2NWT1E6MQ#gid=0
Thanks in anticipation
is it possible to change the from address so that it is different from the default option connected to your google account? I have all the forms set up on my personal google ID and I need the confirmation emails to go out from my work email ID. I do not want to have to migrate all existing forms and data to my work email ID.
ReplyDeleteI guess its best to transfer the ownership in that case. Its easy by going to the form - choose share then select the business email id to share the form with. By default it will give edit access, however you can choose is owner option in that setting. That way same forms will also be owned by business account. then you can follow the authorization steps inside business account to manage those forms.
DeleteIt may be tedious if you have too many forms, but I do not see any other alternative as of now. Sending email with a differnt from address can be a security and spamming issue therefore it may not be allowed from google apps.
BTW I am assuming you business email is on google apps, otherwise you may not be able to share the ownership.
Let me know how it goes.
I got this question in email and thought of adding it to the comments since many others may also be looking for HTML emails
ReplyDeleteName :: Abdul Kadir
Question :: I read your article about "How-To Send Auto Reply Email on Submission of Google Docs Contact Form" in http://www.fromdev.com/2012/06/how-to-send-auto-reply-email-on.html.
And I glad it works for me. Previously, i'd like to turn my page with PHP mail() function for giving a feedback to users who fill the form, but looks like the method="POST" trigger is used by google on the form that I put on the same page. But the point why I use PHP, is because I can made the feedback email as HTML.
Can I do it with the Google Script (Java Function) so i can make my available HTML "thanks page" appears on the feedback email? at least do you have an external link or maybe you already made that tutorial before?
Really appreciate if you reply.
Abdul,
DeleteThanks for reaching out. You can easily send HTML format emails using google api. Replace this line
MailApp.sendEmail(email, subject, message, {replyTo:myemail});
with this one
MailApp.sendEmail(email, subject, message, {replyTo:myemail, htmlBody:
"<html>Paste your HTML content here</html>'>"});
Hope this helps.
For more details on this check the google document for this API - https://developers.google.com/apps-script/class_mailapp
can i embed another doc form into the auto reply email?
ReplyDeleteShafeeque - I guess You mean to send a form inside the email. That can be easily done using the embed HTML code from google docs. Copy the html code into the email send function like this.
DeleteMailApp.sendEmail(email, subject, message, {replyTo:myemail, htmlBody:
"<html>Paste your HTML content here</html>'>"});
when i use the option for embed doc into website it gives an iframe code (<iframe src=......etc).. And while i put this iframe code into auto reply email as like u said, it shows an error in the script editor like this.....( line 38 missing } after property list)
ReplyDeleteCan you please post your code here? I can review and see what may be wrong.
DeleteHello!
ReplyDeleteThis is great. I have a question. My autoresponse includes my message AND all of the info/answers on my form. How can I only have my response show?
Thanks
JC
HI,
ReplyDeleteNot sure if my message was delivered. Everything is great and I appreciate the wisdom! My auto responder email is sending my message AND all of the info on the form. I only want the user to read my autoresponder message. How do I eliminate the info from the form submission.
Thanks!!
Great Tip FromDev,
ReplyDeleteHope I can apply it to my site. Sorry to be a noob, but where can I find Tools - Script Editor? I looked at the Form maker page and it wasn't there.
Thanks!
while i put iframe code into auto reply email as like u said, it shows an error in the script editor like this.....( line 38 missing } after property list). the code is gicen below.
ReplyDeleteiframe src="https://docs.google.com/spreadsheet/embeddedform?formkey=dFVVZ0plU3FQbDhaR1laaF9teFFGa2c6MA" width="760" height="659" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe
Try to replace all double quotes (") with single (') in this iframe snippet and see if that works.
DeleteIt may look like this
src='https://docs.google.com/spreadsheet/embeddedform?formkey=dFVVZ0plU3FQbDhaR1laaF9teFFGa2c6MA' width='760' height='659' frameborder='0' marginheight='0' marginwidth='0'
Let me know if it still does not work.
Hey I liked your tutorial and applied it but I keep getting 2 errors which are:
ReplyDelete1. Failed to send email: no recipient
2. Cannot read property "namedValues" from undefined
The code is as follows:
function sendAutoReply(e)
{
var myemail="bigpoppa003@gmail.com";
var email="";
var subject="Re:Generating Free Leads";
var message="Hi ~Firstname~, Today, I'm going to share with you a free traffic generation system called LeadsLeap.com. If you have heard about this service and you have not registered your free account, I suggest that you do it now at http://www.leadsleap.com?referid=bigpoppa003 LeadsLeap is an ingenious system that combines the power of contextual advertising and network lead generation. In this system, you are allowed to post ads to 10 levels of network you have built. Unlike traditional network lead generation methods, LeadsLeap only allows members to post their ads in the form of contextual ad. This means your leads do not receive obtrusive ads from their uplines, which is a good thing because no one likes to receive junk ads. Moreover, LeadsLeap sends very informative and useful newsletters to their members. I've saved some of the newsletters for future reference. I'm sure you will benefit from the newsletter too. This is a free service. Register your account now at http://www.leadsleap.com?referid=bigpoppa003 Regards, Punith";
try {
for(var field in e.namedValues) {
message +=field + ' :: '
+ e.namedValues[field].toString();
if (field == 'Subject') {
subject += e.namedValues[field].toString();
}
if (field == 'Email') {
email = e.namedValues[field].toString();
}
}
MailApp.sendEmail(email, subject, message, {replyTo:bigpoppa003@gmail.com});
} catch(e){
MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission. No reply was sent.", e.message);
}
}
In addition the picture of my list is as follows:
http://gyazo.com/e020037d021e11fea17c9abb0e50defd
The picture of the above code in the script is as follows:
http://gyazo.com/d4abc0f8d97fd414224ca4dec1a17769
Also, notice that I put ~FirstName~ in the message field. That is because I was trying to figure out if that would put the recipient's name in the ~FirstName~ part. But i dont think it would work. Do you know a way to do that?
Thanks for your comments, let me try to help here. Please change the line
Delete{replyTo:bigpoppa003@gmail.com}
to
{replyTo:myemail}
Replace the message text with a small test message and see if it works. If it does than I guess the message text need to be constructed based on max limit if not then make sure you use the exact form as we have in the tutorial.
DeleteI reviewed your form and it has only two fields. Subject and Message fields are missing in that form.
The ~FirstName~ will not work since its just a part of string. If you want to replace it with name of person than you may need to do some more coding in the form. e.g.
DeleteStep 1: add a First Name field in form.
Step 2: add a variable in your code to read first name field. Just like we are doing for Subject and Email.
Step 3: Construct the message with First name variable like this
"first part of message" + firstNameVariable + "second part of message";
Hey I get 2 errors when I submit form:
ReplyDelete1. Failed to send email: no recipient
2. Cannot read property "namedValues" from undefined.
Here is a picture of the code:
http://gyazo.com/d4abc0f8d97fd414224ca4dec1a17769
Here is a picture of the contact list the code is assigned to
http://gyazo.com/e020037d021e11fea17c9abb0e50defd
Here is the code copied and pasted:
function sendAutoReply(e)
{
var myemail="bigpoppa003@gmail.com";
var email="";
var subject="Re:";
var message="Hi ~Firstname~, ";
try {
for(var field in e.namedValues) {
message +=field + ' :: '
+ e.namedValues[field].toString();
if (field == 'Subject') {
subject += e.namedValues[field].toString();
}
if (field == 'Email') {
email = e.namedValues[field].toString();
}
}
MailApp.sendEmail(email, subject, message, {replyTo:bigpoppa003@gmail.com});
} catch(e){
MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission. No reply was sent.", e.message);
}
}
In addition notice that in my message there is a Hey~FirstName~ . THis is because I was trying to get google to recognize the recipient's name. But I don't think that code would work. Do you know a way for that?
Also here is what my Form looks like on Display:
ReplyDeletehttp://gyazo.com/9295b2866d453528aabff0662cdcca81
Hi thanks vm for the tutorial. Do you know if there is anyway to pre-populate the form responses with the recipients contact details (name, email address etc) rather than have them enter them manually? This could be taken from another spreadsheet perhaps.
ReplyDeleteThanks for your help
It can be difficult. You could do it if every user accesses a separate link. Here is a simple trick you can use. Send each user a separate link with all pre-population details and when they use that link to fill up the form the fields will be already populated using simple trick described here - http://support.google.com/drive/bin/answer.py?hl=en&answer=160000
DeleteHi. Thanks for the tutorial. Do you know if there is anyway to pre-populate a google form with the recipients contact details, rather than have them enter them manually. I'd be lloking to obtain those contact details from another google spreadsheet.
ReplyDeleteThanks for your help
Hi Sachin,
ReplyDeleteThanks so much for this great tutorial. My autoresponse includes my message AND all of the questions/answers on my form. How can I remove these fields and answers on the auto reply? I only want to send them a thank you note for filling out the form but i dont want to include their answers on the auto reply. Please help.
Thanks,
JCL
I need the same thing. Did you figure it out?
DeleteComment (//) line 24 and 25 in this code and that should remove the fields from message. Sorry for the late reply. Hope this helps others.
DeleteArgument too large: subject
ReplyDeletehow do i fix this
Please reduce the size of subject field. Try putting a small text in subject value. I would recommend using a drop down value so users can type. Or may be a max limit text field.
DeleteI do not have a subject field in my form it is a registration form for user to register for classes. i deleted the subject part from the code
Deletemy code
var myemail = "abc@youmail.com";
//Leave this field blank - it will be auto populated from "Email" field in
// your contact form. Make sure you have a "Email" Field in your contact form.
var email = "";
// This is going to be the subject of reply email
// You can change it as per your requirements
//var subject = "Re: ";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var message = "Thanks for contacting FromDev.com. We will get in touch with you shortly. \n\n-----\n\n";
try {
for(var field in e.namedValues) {
message += field + ' :: '
+ e.namedValues[field].toString() + "\n\n";
if (field == 'Subject') {
subject += e.namedValues[field].toString();
}
if (field == 'entry.8.single') {
email = e.namedValues[field].toString();
}
}
// We are using Java MailApp util of Google Apps Script
// that sends the email.
MailApp.sendEmail(email, message, {replyTo:myemail});
} catch(e){
MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission. No reply was sent.", e.message);
}
}
Make sure the function signature is like this
Deletefunction sendAutoReply(e)
the variable e is passed by google API.
thats exactly how i have it and i still get that error i cant figure it out. there is no subject field
DeleteCan you please share you contact form with software.wikipedia at gmail.com
DeleteI will try to see if I can help you resolve this.
I sent you an email with the subject DualActionTactics. thanks for all the help!
DeleteI have set up the for the same as you have suggested even though this is not quite what I am after just so I can figure out the coding. I am still getting an error message 'Cannot read property "namedValues" from undefine.'
ReplyDeleteMy coding is
function sendAutoReply(e)
{
var myemail = "enlighten.life.coach.info@gmail.com";
var email = "";
var subject = "Re:Wellness Products and Community Projects";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var message = "Thanks for contacting Enlighten Life Wellness Products. We will get in touch with you shortly. \n\n-----\n\n";
try {
for(var field in e.namedValues) {
message += field + ' :: '
+ e.namedValues[field].toString();
if (field == 'Subject') {
subject += e.namedValues[field].toString();
}
if (field == 'Email') {
email = e.namedValues[field].toString();
}
}
MailApp.sendEmail(email, subject, message, {replyTo:myemail});
} catch(e){
MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission. No reply was sent.", e.message);
}
}
Your help is very much appreciated!
Natalee - Can you share the contact form with me please? I can check and let you know if there is something missing. The does not look wrong at a glance.
DeleteNot sure if you can view this link without logging in?
ReplyDeletehttps://docs.google.com/spreadsheet/viewform?pli=1&formkey=dDY2c0RodHpZbUVJU0xiZFBVXzVYZVE6MQ#gid=0
Hope that works?
I just filled up the form and go a auto reply from you. It seems to be working. Have you tested it with your own account email just to see if that works out.
DeleteIs there any specific scenario where it does not work
--------Here is the reply I got--------
Thanks for contacting Enlighten Life Wellness Products. We will get in touch with you shortly.
-----
Name :: Sachin FromdevEmail :: software.wikipedia@gmail.comSubject :: Wellness ProductsMessage :: Natalee, This is Sachin, just doing a test on the form. Please ignore this message. Timestamp :: 11/20/2012 2:51:49
I have a question..... if the Email column has a formula.... the app script doesn't work... cuz it gets the formula not value, so... How can i fix it?
ReplyDeleteThanks in Advance....
Store the value of formula in a variable and pass it to the function.
DeleteFeel free to share your formula and I can review.
Hi,
ReplyDeleteThank you for the script. Is it possible to Cc the form, I have a client who wants to receive a copy of the registrations. Not quite sure why as they can access the spreadsheet, but who am I to ask. Thanks
Thanks for the script I a have form which i would like to send a specific message base on the product a customer select.Such that when a customer select product A an auto reply with the price of the product will be send to customer base on the product selected
ReplyDeleteHey! Thanks for the tutorial. But I don't want the people who had submmitted the entry to receive what they had entered in the form. What do I do?
ReplyDeletehow do you modify the information submitted in the form?
ReplyDeletei'm looking at this section of your code and trying to figure out how to only include the responses to some of the questions, but not all.
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
// var message = "Thanks for contacting FromDev.com. We will get in touch with you shortly. \n\n-----\n\n";
try {
for(var field in e.namedValues) {
message += field + ' :: '
+ e.namedValues[field].toString() + "\n\n";
if (field == 'Subject') {
subject += e.namedValues[field].toString();
}
if (field == 'entry.8.single') {
email = e.namedValues[field].toString();
}
}
Sorry for late reply, It can be done in same way we are checking for each field. Just add a if condition check for MailApp.send method and send different emails for different conditions.
DeleteThe for loop to get a variable dump was invaluable to me to figure out how to pick out a specific variable (use the label name, not the actual variable name). Thank you! Google's pseudo programming is quite frustrating when you're used to just programming it for yourself...
ReplyDeleteBTW, I almost skipped over this tutorial because you called it Java. It's *not* Java. It's Javascript. They're not at all the same. ;)
Some asked me about changing the content in auto reply so wanted to add it in this post :
ReplyDeleteYou should be able to reply with any content you want using same script. Just make the variable with a new content. Make sure you use javascript string contact operator if text is too large.
for example
var message = ' Some text you want to send ' + ' Some more text ' + ' even more text';
this should send the message with very large text too. Most of the time problem may happen if you try to construct a string in one shot. Instead try the above approach by using plus operator and stick to around 40 characters in a string.
Hope this helps.
Regards,
Sachin
Sachin,
ReplyDeleteThank you for this script how it does not work: I keep getting an error: "Failed to send email: No Recipient"
I've isolated the cause, but I'm not seeing why it's a problem. The script is not looping through the fields. When I debug I get a error reporting that 'e' is undefined and so is 'field'
Here's the script:
function sendAutoReply(e)
{
// Remember to replace abc@youmail.com with your own email address
// This will be used to send you a email notification in case of error on form
// for example if someone entered a wrong email address.
var myemail = "terry@iproduceleads.com";
//Leave this field blank - it will be auto populated from "Email" field in
// your contact form. Make sure you have a "Email" Field in your contact form.
var email = "";
// This is going to be the subject of reply email
// You can change it as per your requirements
var subject = "Re: ";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var message = "Thanks for contacting FromDev.com. We will get in touch with you shortly. \n\n-----\n\n";
try {
for(var field in e.namedValues) {
message += field + ' :: '
+ e.namedValues[field].toString() + "\n\n";
if (field == 'Email') {
email = e.namedValues[field].toString();
}
//if (field == 'Subject') {
// subject += e.namedValues[field].toString();
// }
}
// We are using Java MailApp util of Google Apps Script
// that sends the email.
MailApp.sendEmail(email,subject,message, {replyTo:myemail});
} catch(e){
MailApp.sendEmail(myemail,email, e.message);
}
}
here's the form: https://docs.google.com/forms/d/16iCRb7BU3fo3oeQVtGcU8xq3fiVHPfGTaNmvLzU_uiM/viewform
The script does work when I replace email = ""; with an actual email address. This tells me the script is not reading through the fields on the form.
I only have two fields in the google docs spreadsheet. First Name and Email
Any thoughts?
Cordially,
Terry
PS. Thank you for the script and willingness to help out.
just tried your form. didnt work :(. Please make sure the field names are case sensitive. The email field should be named 'Email' according to this code.
Deleteif (field == 'Email') {
email = e.namedValues[field].toString();
}
Let me know if you are able to resolve this. Otherwise we may need to try giving more authorization on the form to me.
Also noticed one more thing. The catch block should be like this.
Deletecatch(e){
MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission. No reply was sent.", e.message);
}
This is required since you will get notified in case the fields are having some data issues. May be someone enters a garbage in email field and its not able to send email.
Hey,
ReplyDeleteI keep getting the following error: Cannot read property "namedValues" from undefined.
or: Failed to send email: no recipient
I can pay you via paypal if you can help me fix this asap
here is my form: https://docs.google.com/forms/d/1qx1-bWS4oVkPxex6y2db5Mr4N2OGkkpYHIor4HnyW1k/viewform
and here is my code:
function sendAutoReply(e)
{
var myemail = "erikegelko@gmail.com";
var Email = "";
var subject = "Re:Test Email";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var message = "Thanks for contacting Enlighten Life Wellness Products. We will get in touch with you shortly. \n\n-----\n\n";
try {
for(var field in e.namedValues) {
message += field + ' :: '
+ e.namedValues[field].toString();
if (field == 'Subject') {
subject += e.namedValues[field].toString();
}
if (field == 'Email') {
email = e.namedValues[field].toString();
}
}
MailApp.sendEmail(Email, subject, message, {replyTo:myemail});
} catch(e){
MailApp.sendEmail(myemail, "Error in Auto replying to contact form submission. No reply was sent.", e.message);
}
}