LoginSignup
1

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-04-13

私が運営しているサイトの問い合わせフォームを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()が呼び出されるようになります。

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
1