Google Setup

Steegle.com now offers two new services:
Hassle free setup with minimum of effort.

RSS Feed

If you wish to receive updates from steegle.com please subscribe to the
RSS Feed

Recent site activity

Websites‎ > ‎Google Sites How-tos‎ > ‎

Google Apps Script - Contact Us Form - E-mail

posted 9 Jul 2010 10:11 by Stephen Hind   [ updated 2 Jan 2012 11:20 by Stephen Hind ]

Google now provide scripts you can add to spreadsheets, so now when a Google Sites visitor uses your Google Spreadsheet Form you can have the response e-mailed to you, rather than having to go to the spreadsheet.


Instructions

  1. Go to Google Docs (either http://docs.google.com for a personal account or http://docs.google.com/a/example.com for Google Apps uses, where example.com is your domain)

  2. Use the Create New drop-down menu then choose Form to make a new form

  3. In the form you need to make three required questions

    1. Name
    2. E-mail Address (so you can get back in touch)
    3. Message (or whatever you want to call it)

    For further information on how to create forms see Forms: Creating Forms - Google Docs Help Centre

  4. Save your form and return to Google Docs

  5. Once back at Google Docs refresh the document list and open the new spreadsheet created for the form

  6. Once in the spreadsheet use the Tools menu, then Scripts, then Insert... 

  7. Find the Contact Us Form Mailer in the Public section of the Script Gallery and use the Install button

  8. When the Authorization Required dialogue box appears use the Authorize button

  9. The script will now show as installed on the list of public scripts, so use the Close button to return to your spreadsheet

  10. Use the Tools menu, then Scripts, then Script Editor...

  11. Enter your e-mail address in between the quotation marks on the 
    var recipient "";
    line, so it should now look something like
    var recipient "someone@example.com"
    ;
    and use the Save button (it's a little icon of a floppy disc)

  12. While still in the Script Editor use the Triggers menu, then Current script's triggers

  13. In the Current Script's Triggers box use the No triggers set up. Click here to add one now link

  14. From the drop-down boxes make sure that contactUsMailer, From spreadsheet and On form submit are selected and use the Save button.

  15. Close the Script Editor and return to your spreadsheet. While you're there save the spreadsheet and close it.

  16. Go to your Google Site and use the Edit Page button, then the Insert menu and then Spreadsheet form

  17. Choose the form you have created and use the Select button, then choose the display options you want for the form (width, height title, border, etc) and then use the Save button

  18. Use the Save button (top-right corner) to save the page and then you can test your form.

I have included the form below, so please do use the form to let me know what you think of the script.

The Form

Screen Shots

click for larger images

Inserting a script

Script Gallery

Script Authorization

Script Installation Confirmation

Script Triggers Menu

Current Script's Triggers


The Script

function contactUsMailer(e) {
  //  This script e-mails the contents of a form to a given recipient
  //  The form must have three fields in the order of: name; e-mail address; and message
  //  You must change the recipient variable below to your e-mail address
  try {
    var recipient = "";
    var timestamp = e.values[0];
    var name = e.values[1];
    var email = e.values[2];
    var message = e.values[3];
    var body = name+' <'+email+'> sent the following message: '+message;
    var bodyHTML1 = '<p>'+name+' <a href="mailto:'+email+'">'+email+'</a> sent the following message: </p>';
    var bodyHTML2 = '<blockquote>'+message+'</blockquote>';
    var bodyHTML3 = '<p>Sent by the <a href="http://www.steegle.com/">Steegle.com</a> Contact Us Form Google Apps Script</p>';
    var advancedArgs = {htmlBody:bodyHTML1+bodyHTML2+bodyHTML3 , replyTo:email};
    MailApp.sendEmail(recipient, "Contact Us Form", body, advancedArgs);
  } catch(e){
    MailApp.sendEmail(recipient, "Error - Contact Us Form", e.message);
  }
}