代码之家  ›  专栏  ›  技术社区  ›  Hani Almutlaq

谷歌电子表格中的JavaScript功能,用于向电子邮件发送二维码

  •  0
  • Hani Almutlaq  · 技术社区  · 2 年前

    我们正在计划一个活动,要注册,你必须填写一份谷歌表格,填写后,电子表格的“应用程序脚本”中有这个功能,可以生成二维码并将其发送到你的电子邮件,我也触发了,但该功能不起作用,你有什么想法吗?

    功能:

    function sendQrCodeEmails() {
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      var data = sheet.getDataRange().getValues();
      var qrCodeUrlPrefix = ''https://chart.googleapis.com/chart?cht=qr&chs=150x150&chl=';
    
      for (var i = 1; i < data.length; i++) {
        var email = data[i][2]; // third column is the email
        var name = data[i][1]; // second column is the name
        var qrCodeUrl = qrCodeUrlPrefix + encodeURIComponent(email);
    
        // Send Email with QR Code
        MailApp.sendEmail({
          to: email,
          subject: 'Your Event QR Code',
          htmlBody: 'Hello ' + name + ',<br><br>Thank you for registering. Please find your 
          QR code below.<br><img src="' + qrCodeUrl + '"><br>Best Regards,<br>Event Team'
        });
      }
    }
    

    谢谢你抽出时间。

    1 回复  |  直到 2 年前
        1
  •  0
  •   BugHunter    2 年前

    我认为您在body标记中存在语法错误和一些问题。

     function sendQrCodeEmails() {
          var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
          var data = sheet.getDataRange().getValues();
          var qrCodeUrlPrefix = 'https://chart.googleapis.com/chart?cht=qr&chs=150x150&chl=';
        
          for (var i = 1; i < data.length; i++) {
            var email = data[i][2]; // third column is the email
            var name = data[i][1]; // second column is the name
            var qrCodeUrl = qrCodeUrlPrefix + encodeURIComponent(email);
        
            // Send Email with QR Code
            MailApp.sendEmail({
              to: email,
              subject: 'Your Event QR Code',
              htmlBody: 'Hello ' + name + ',<br><br>Thank you for registering. Please find your QR code below.<br><img src="' + qrCodeUrl + '"><br>Best Regards,<br>Event Team'
            });
          }
        }