A script that sends a confirmation email when a form created in Google Drive (formerly Google Docs) is submitted.

This content is from 2012. The steps may no longer work.

When creating a website for free, one of the options that comes to mind isGoogle Sitesis.
Google Sites allows you to create websites without specialized knowledge or building software.
While its design is somewhat limited, it still offers more than enough functionality for disseminating information online. By integrating with other Google applications (such as Calendar, Drive, and Docs), it's easy to display detailed information like store hours and schedules on a website, and to easily output information such as inquiries and survey forms. This groupware allows you to use all of these applications comprehensively.Google AppsIt's really convenient, and I use it a lot myself.

By the way, regarding the aforementioned inquiry and survey forms, integrating them into Google Sites is probably something anyone can easily do. However, these forms lack convenience afterward.
In other words, when a form is filled out and submitted, neither the submitter nor the administrator receives an email notification. Therefore, the administrator has to constantly check Google Drive to see if anything has been entered into the form. This is inconvenient. And from the submitter's perspective, simply filling out the form and pressing the [Submit] button only to be met with a simple "Thank you" message is quite disappointing.

I know someone who runs a website business using Google Sites, and they asked me for help with automatically sending emails as soon as a form is submitted. I helped them integrate a script for this purpose. Recently, they asked me to do the same thing with a different form, so I integrated the script again. Regardless of the script's content, the integration process isn't that difficult, so I'll describe the method below. You can use the script by copying and pasting what's written in the text and modifying only the necessary parts.

When a form created in Google Drive (formerly Google Docs) is submitted, a confirmation email will be sent.


1. First, create a form such as an inquiry form or survey form in Google Drive.


2. From the "Tools" menu on the menu bar, select "Script Manager".


3. Click "New" at the bottom of the window that appears. The above will be displayed, so select "Empty Project" at the top of the left column.


4. ワークシート内にすでに記されている数行(function myFunction() {})をすべて消し、以下のコードをコピー&ペーストして、「フロッピーディスク」のアイコンをクリックして保存する。カスタマイズや変更は、上図を参考に。

function sendMailByFormSubmitted() {
Logger.log('sendMailByFormSubmitted() start');// 件名、本文
var subject = "様 お問い合わせ・お申込み ありがとうございます/XYZ Company";
var body = "この度は、お問い合わせ・お申込みをいただき、ありがとうございます。nこちらから、別途メールでご連絡いたしますので、しばらくおまちくださいませ。nn株式会社 XYZカンパニーnnn=========================n▼ お問い合わせ・お申込み内容 ▼n=========================n";// メールアドレス入力カラム名の指定
var MAIL_CLMN_NAME = 'メールアドレス';
var APPLICANT_NAME = 'お名前(漢字)';// メール送信先(管理者等)
var mail_admin = "asdfqwerty@xyzcompany.com";
var mail_cc = mail_admin;
var mail_reply = mail_admin;
var mail_to = '';

try{
// スプレッドシートの操作
var sh = SpreadsheetApp.getActiveSheet();
var rows = sh.getLastRow();
var cols = sh.getLastColumn();
var rg = sh.getDataRange();
Logger.log("rows="+rows+" cols="+cols);

// メール本文作成と送信先メールアドレス取得
for (var j = 1; j var clmn_name = rg.getCell(1, j).getValue(); // カラム名
var clmn_value = rg.getCell(rows, j).getValue(); // 入力値
body += ( clmn_name + " : " + clmn_value + "n" );

if ( clmn_name === MAIL_CLMN_NAME ) {
mail_to = clmn_value;
}
if ( clmn_name === APPLICANT_NAME ) {
apname = clmn_value;
}

}

// メール送信
if ( mail_to ) {
MailApp.sendEmail(mail_to, apname + subject, body, {cc : mail_cc, replyTo : mail_reply});
}else{
MailApp.sendEmail(mail_admin, "error spreadsheet none mailaddress", body);
}
}catch(e){
MailApp.sendEmail(mail_admin, "error spreadsheet func: sendMailByFormSubmiited()", e.message);
}
}


5. Next, select "Current Script's Triggers" under "Resource".


6. The "Current project's triggers" window will appear. Click "Add a new triggers," change the event to "On Form Submit," give it a suitable name, and click "Save."


7. You will be asked to authenticate the first time you use it, so click "Authorize".

It's finished.
All that's left is to paste the form with the script embedded into your website, and you're good to go.