I'm getting the error when I run the code below:
Failed to send email: no recipient
The code is embedded in a google spreadsheet project linked to a google form.
The error rises on the MailApp.sendEmail(email, subject, body, {htmlBody: body, attachments: pdf});
call, even if the value of the email variable is correct. Moreover, the recipient receives the email but then the code doesn't continue.
Code provided below:
// When Form Gets submitted
function onFormSubmit(e) {
//Get information from form and set as variables
var cognome = e.values[1].toUpperCase();
var nome = e.values[2].toUpperCase();
....
var email = e.values[9].toString();
// Prepare a pdf document. Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
var subject = "Subject";
var body = '....';
Logger.log(email);
MailApp.sendEmail(email, subject, body, {htmlBody: body, attachments: pdf});
// Delete temp file
DriveApp.getFileById(copyId).setTrashed(true);
}