Help us understand the problem. What is going on with this article?

Google Formで問い合わせが来たときに、その内容をGmailに通知する

More than 3 years have passed since last update.

私が運営しているサイトの問い合わせフォームをGoogle Formにしたのですが、問い合わせが来たときにGmailに通知がいくようにしました。

Google Formにはデフォルトでもメール通知機能がありますが、「新しい回答があります」という内容のメールが来るだけで大変わかりにくいものでした。

スクリプトエディタを開く

こんな感じのコードを書きます。

function sendForm(e){
  var subject = "問い合わせがありました";  //件名
  var body = "問い合わせ内容\n------------------------------------------------------------\n\n";  //本文
  var to    = "youremail@example.com";

  var res = e.response;
  var itemResponses = res.getItemResponses();
  for (var j = 0; j < itemResponses.length; j++) {
     var itemResponse = itemResponses[j];

     body += itemResponse.getItem().getTitle() + "\n";
     body += itemResponse.getResponse() + "\n\n";
  }
  MailApp.sendEmail(to, subject, body);   //メールを送信
}

トリガーの設定

スクリーンショット 2016-04-13 23.54.32.png
このようにトリガーを設定すればOKです。
フォームに新しい回答がきたときにsendForm()が呼び出されるようになります。

参考

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away