Harlan Stevens
Harlan Stevens

Reputation: 3

Form Notification for Teachers when Students Fill out Google Form

I'm making a website for school to connect students and teachers. Teachers fill out a Google Form asking for service (grading papers...) and it is connected to Google Spreadsheets. Then a student can see that Spreadsheet and sign up on a different Google Form to help the teacher, and that response is recorded in the same Google Spreadsheet. When the student submits his/her Google Form, I want the teacher to be notified by email that a student signed up to help them. How can I send that notification? And I don't want the notification to come from my own school address. Is that possible? Here is the Google website: https://sites.google.com/fcpsschools.net/jmhsservicesignup/subjects/math

This is the code I have so far:

function sendEmails() {

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tutors 
Signed Up");

  var startRow = sheet.getLastRow();  // First row of data to process

  var dataRange = sheet.getRange(startRow, 1, 1, 5)
  // Fetch values for each row in the Range.

  var data = dataRange.getValues();

  for (i in data) {

    var row = data[i];

    var emailAddress = row[3];       // Second column

    var tutor = row[0];

    MailApp.sendEmail(emailAddress,"Tutor Request Filled",""+tutor+" has accepted your request to be tutored! Please notify"+tutor+" if anything changes.");

  }
}

The getLastRow doesn't seem to work, and the email sends from my own address, not a Google forms notification if that is even possible.

If this is impossible I might just make the students send the email to the teacher, but I really want to automate the process. If you can think of a workaround, that would also be awesome.

Upvotes: 0

Views: 232

Answers (1)

e__n
e__n

Reputation: 717

Adding to what Sandy Good and Guilherme mentioned. Here are a few more tips:

Not clear what data you're trying to get in your function. Are you trying to grab the data from the form submission? In that case you need to set up a trigger from the scripts menu, and connect it to the function (function needs to have an 'event' argument, usually called e).

function processFromSubmission(e) {//get data from e}

Apologies if you're not trying to do that. What happens when you Log sheet.getLastRow()?

Ask the school if they can get you another email address to use for this form, something like [email protected]. Follow the steps here to set up your alias. Do it for the gmail account that "owns" the spreadsheet these forms are sending data to.

Make sure your alias is set up properly. You should be able to see it in the "from" dropdown menu when you compose an email. Also try running the code Logger.log(GmailApp.getAliases()) and check the log to see that it's available.

Use GmailApp.sendEmail to send email, not MailApp.sendEmail. They're almost the same, but it looks like the MailApp version doesn't let you send from an alias. You can specify the 'replyTo' email as well if you want to set it to something else, like the student filling out the form or whatever (still not clear exactly what you're trying to set up!).

Send email like:

GmailApp.sendEmail(emailAddress, subject, body,
   {replyTo: replyToEmailAddress_can_be_any_email,
    from: '[email protected]'
 });

Note: your link didn't open.

Upvotes: 0

Related Questions