I have a google apps script developed for when a user submits a form. Its an app script from the spreadsheet attached to form responses. In the script I send back an acknowledgement email. Just recently, I have started receiving some error message from Google Script (on some, but not all responses):

Your script, blahblahblah, has recently failed to finish successfully. A summary of the failure(s) is shown below. To configure the triggers for this script, or change your setting for receiving future failure notifications, click here.

Start: 5/21/19 4:57 PM
Function: sendResponseToPlayer
Error Message: Failed to send email: no recipient (line 97, file "blahblahblah")
Trigger: formSubmit
End: 5/21/19 4:57 PM

Google Apps Script

Also recognize:

  • that in my "Sent Mail" box, there is an email sent to the respondent that the script sends email to.
  • the recipient did not receive the email
  • the script has not changed in the past 4 weeks
  • the file attachments have not changed in the past 4 weeks
  • the error is now occurring with each form respondent

Why would these errors start creeping up? Why would I get the email in my Sent Mail box if there was an error? What do I need to change in the script?

Thanks in advance for any insight provided.

function sendResponseToPlayer(e) {

  var values = e.namedValues;

  var pfname = values['First Name'].toString();
  var plname = values['Last Name'].toString();
  var pyn = values['Playing?'].toString();
  var pem = values['Email Address'].toString();

  // Acknowledge their response
  var subject = 'Player Response ';

  var hbody = '';
  hbody += "<p>Thank you, " + pfname + ". You have answered \"" + pyn + "\" to playing this week.</p>";

  // Add document text
  var body = DocumentApp.openByUrl('https://docs.google.com/document/d/123abc/edit').getBody();
  var bodyTextElement = body.editAsText();
  var bodyString = bodyTextElement.getText();

  hbody += "<p>" + bodyString + "</p>";

  // Add spreadsheet text
  var sheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123/edit#gid=0');
  var values = sheet.getActiveSheet().getDataRange().getDisplayValues();

  for (var i = 0; i < values.length; i++) { // length of first dimension of 2d array
    for (var j = 0; j < values[i].length; j++) { // length of dimension of specific row
        hbody += values[i][j] + "    ";
      hbody += "<br>";

  hbody += "<p>Please see attachments.</p>";

  var fid = '789xyz';
  var file = DriveApp.getFileById(fid);

  var fcal = 'xyz789';
  var calfile = DriveApp.getFileById(fcal);

  var replem = 'me@gmail.com';

            to: pem,
            replyTo: replem,
            subject: subject,
            htmlBody: hbody,
            attachments: [file.getAs(MimeType.PDF),calfile.getAs(MimeType.PDF)],
            name: 'me'

1 Answer 1


I think it's just an error handling thing.

I'm running into that same (or similar) error and it seems to be happening when there is only one email address to loop through. Like it hits a blank row and freaks out.

When there are multiple address/multiple emails to send, there is no error message.

Though I do not know how to handle that error... but if that sparked an idea and you solve it, please do share! :)

EDIT: I fixed mine by putting this right in front of the MailApp.sendEmail

if (email == "") {

...so for you, just change "email" to "pem", drop it in, and that should get rid of the error message! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.