Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending QR code from Google Sheets to email address

I have a simple Google Form setup to capture data, pull it into a doc and then send a confirmation email to the respondee.

I've recently been using the Sheets method for automatically creating QR codes in the form response sheet using =image("https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl="&K2). The information in 'K2' is a very simple 20 digit number and I'd like the QR code to be sent in the confirmation email.

The email uses some very basic HTML and I guessed that the QR code might need it's own <img> tag since others bits of data pulled through are just strings but I wouldn't know where to start with the img source. Can anyone suggest the right method for achieving this or if there's an easier alternative? I'm new to Google Apps Script so any help would be much appreciated.

Here is some sample code:

function sendQRCode() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");

var data = sheet.getRange(sheet.getLastRow(), 1, 1, sheet.getLastColumn()).getValues(); // Range (last entry submitted)

for (var i in data){
  var row = data[i];
  var custemail = row[14];
  var qrCode= row[15];

  var mailBody1 = '<p>Hi ' + row[2] + ',<br /><br />Thanks for your response.<br /><br />Here is a QR code with the information you require:</p>' + qrCode + '<p>Kind regards,</p><p>The Team</p>'

  if ((row[9]=="Yes") && (row[13]=="Yes")){
     MailApp.sendEmail(custemail,"Your QR Code",mailBody1,{'htmlBody' :mailBody1,noReply: true});}
 }
}
like image 282
limonvnx Avatar asked Nov 28 '25 19:11

limonvnx


1 Answers

You have to wrap the image (the URL) with an <img tag in the email body. Something like <img src='"https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl=' + row[10] + '"' /> in the email should work.

like image 84
XEB Avatar answered Dec 01 '25 20:12

XEB