2016-02-27 96 views
0

我試圖讓Google表單在我們的網站上自動通知我們,當用戶完成表單並返回他們輸入的簡明電子郵件中的數據時。我不喜歡谷歌通知你的方式,它只是鏈接到你的形式來查看答覆。我在網上搜索,發現這個代碼:Google表格腳本只能在一個文件上工作

function sendFormByEmailPrayer(e) 
{  
    // Remember to replace XYZ with your own email address 
    var email = "[email protected]"; 

    // Optional but change the following variable 
    // to have a custom subject for Google Docs emails 
    var subject = "Prayer Form Form Submitted"; 

    // The variable e holds all the form values in an array. 
    // Loop through the array and append values to the body. 

    var s = SpreadsheetApp.getActiveSheet(); 
    var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0]; 
    var urlToDoc = SpreadsheetApp.getActive().getUrl(); 
    var body = ""; 
    body = body + "Link to Document: " + urlToDoc; 

    var message = body + "\n\n" + ""; 

    // Credit to Henrique Abreu for fixing the sort order 

    for(var i in headers) 
    message += headers[i] + ' = '+ e.namedValues[headers[i]].toString() + "\n\n"; 

    // This is the MailApp service of Google Apps Script 
    // that sends the email. You can also use GmailApp here. 

    MailApp.sendEmail(email, subject, message); 

    // Watch the following video for details 
    // http://youtu.be/z6klwUxRwQI 

    // By Amit Agarwal - www.labnol.org 
} 

在表單提交截圖: enter image description here

據我的一個表上的偉大工程,但是當我複製並粘貼此工作代碼我們其他的6種形式,它根本不起作用。我如何通過我們的7種表格來實現這個功能?提前致謝。

+0

您是否在其他腳本中安裝了「On Form Submit」觸發器?在代碼編輯器中,你需要點擊「Resources」菜單,然後選擇「Current Project Triggers」,然後添加一個新的觸發器,並選擇函數名稱。我沒有看到特定於某個Google電子表格或表單的代碼。如果代碼在一個地方工作,並且不在另一個地方工作,並且代碼是通用的,那麼它不能是腳本本身。 –

+0

是的表單提交是所有其他腳本。 OP發佈的屏幕截圖。 是的,這就是爲什麼我很困惑。代碼是非常通用的,它不能作爲腳本,但我不知道是什麼原因造成的。 –

回答

0

那麼我發現比上面提供的代碼更好的解決方案。如果您使用新版Google表格,則可以添加一個「加載項」(YourForm - >右上角的三個點 - >加載項)。

從那裏尋找"Simply Send"它會自動發送電子郵件的響應與標題。花了大約5秒鐘來設置我的每一個表格。

相關問題