2013-05-10 170 views
1

我已經查看了很多資源以找出我的腳本出了什麼問題,但沒有任何工作。我正在嘗試在Google表單提交後發送確認電子郵件。好像我的腳本沒有從表單中正確地調用電子郵件地址。
我原來的腳本來自http://acrl.ala.org/techconnect/?p=2343,我修改了我的表單。
這是它看起來像:提交Google表單後發送確認電子郵件

function swykemailconfirm(e) { 
    var userEmail = e.values[10]; //email from column K 
    var firstName = e.values[2]; //first name from column C 
    var lastName = e.values[1]; //last name from column B 
    var test = e.values[4]; //test name from column E 
MailApp.sendEmail(userEmail, 
        "Thank you " +firstName + lastName + "for signing up to take the " + test + "Show What You Know test. " + 
        "Make sure you see Ms. May to get your pass. " + 
        "See you on Thursday in room 32 at 3:30." + 
        "The Math Department"); 
} 

我做一個測試表單提交後收到此錯誤消息的電子郵件: 找不到方法(類)sendEmail(字符串,字符串)。 (6號線,文件「守則」)

搜索這裏Google Forms Confirmation Script一種方式來編輯我的劇本後,我用的建議之一,改變了我的代碼如下:

function swykemailconfirm(e) { 
    var userEmail = e.values["E-mail"][0]; 
    var firstName = e.values[2]; 
    var lastName = e.values[1]; 
    var test = e.values[4]; 
MailApp.sendEmail(userEmail, 
        "Thank you " +firstName + lastName + "for signing up to take the " + test + "Show What You Know test. " + 
        "Make sure you see Ms. May to get your pass. " + 
        "See you on Thursday in room 32 at 3:30." + 
        "The Math Department"); 
} 

我正在一個在提交測試表單後提交此錯誤消息的電子郵件: TypeError:無法從undefined讀取屬性「0」。 (第2行,文件「代碼」)

任何幫助非常感謝!

回答

1

您的原始功能(上)可以通過一個小修改正常工作。因爲sendEmail方法需要傳遞三個參數:收件人(字符串),因此Google Docs向您發送錯誤消息「無法找到方法(類)sendEmail(string,string)。(Line 6,file」Code「)。 ,主題(字符串),主體(字符串)。目前,您只傳遞兩個參數:收件人和正文。查看文檔here

將您的功能修改爲以下內容,一切都應該工作!

function swykemailconfirm(e) { 
    var userEmail = e.values[10]; //email from column K 
    var firstName = e.values[2]; //first name from column C 
    var lastName = e.values[1]; //last name from column B 
    var test = e.values[4]; //test name from column E 
    MailApp.sendEmail(userEmail, 
     "Registration Confirmation Subject Line", 
     "Thank you " +firstName + lastName + "for signing up to take the " + test + "Show What You Know test. " + 
     "Make sure you see Ms. May to get your pass. " + 
     "See you on Thursday in room 32 at 3:30." + 
     "The Math Department"); 
} 

希望有所幫助!

相關問題