Embedded Google form in email?

和自甴很熟 提交于 2019-11-29 05:02:21
Mogsdad

To use forms embedded in emails, the email client needs to support html forms. Outlook has its own forms, but does not support the html form element (reference). I haven't found a reference for iPhone, but it's likely that it also limits the html support. (I use the gmail client on my phone... it supports forms.)

If you're using the code from Send form by email and track responses in spreadsheet, then you can extend your script to provide a doGet function for users that don't have HTML Forms support in their email clients.

The previous gist has been updated with these changes. (Actually, the gist already had the doGet() function.)

Code.gs

Extend this code by adding a doGet() function, which will host the exact same form that you're embedding in the email.

/**
 * GET handler to provide alternate online form.
 */
function doGet() {
  // Build survey body
  var template = HtmlService.createTemplateFromFile('emailTemplate');
  template.scriptUrl = ScriptApp.getService().getUrl();
  template.serialNumber = getGUID();  // Generate serial number for this response
  var app = template.evaluate();
  return app;
}

Make the following modification to the sendSurvey() function:

var plainText = 'Please complete this survey online at: ' + scriptUrl;
html += '<p>Alternatively, you may <A href="' + scriptUrl + '"> complete this survey online.</A>';

// Send email form
GmailApp.sendEmail(recipient, subject, plainText, {htmlBody:html} );

Now, recipients without HTML support in their email client will have a plain text message with an address they can paste into a browser, while HTML clients without <FORM> support will have a clickable link to the online form.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!