0

How can I send an automatic email notification to two different email addresses depending on whether a woman or a man has filled in the form? Please can someone help me with a script to check this situation? I have tried with the following script, but it seems missing a ';' and I don't find the problem. And so I don't know if it works.

function sendEmails() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = SpreadsheetApp.getActiveSheet();
      var lastRow = getLastRow();
      var range = sheet.getRange('A'. lastRow);//location cell
      var gender = range.getValue();

      if (gender === 'female'){
         emailAddress = 'email1@gmail.com'
         }

      elseif (gender === 'male'){
         emailAddress = 'email2@gmail.com'
       }

    MailApp.sendEmail({
         to: emailAddress,
         subject: subject,
         htmlBody: message     
       });
    }
0

There is an error on elseif. The correct syntax is else if

  • Thank you for clarifying. I corrected this. But now I get the message that "getLastRow" is not defined. Do you have another hint for me? Thank you in advance – Marion Nov 23 at 17:32
  • It will be worthy that you spend some time learning the basics of JavaScript as Google Apps Script is based on it because we can't explain here all the core concepts and terms. In this case it's required to know what is a function. By the other hand on this site we have a lot of questions & answers for sending emails by using Google Apps Script some of them use a getLastRow method of the the Class Sheet from the Google Apps Script Spreadsheet Service. – Rubén Nov 23 at 18:28

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.