I tried your code modified and added a solution, I created an Installable Trigger event on which on every form submit it will send the attachment along with the body content.
Code.gs on Spreadsheet
function onFormSubmit(e) {
var responses = e.values;
// Email subject file and body
var email = responses[1]; // Assuming the email is on the first response
var fileItem = responses[2]; // Assuming the file is the second response
var subject = "New File Uploaded";
var body = "A new file has been xuploaded.\n\n";
if (fileItem) {
body += responses
MailApp.sendEmail(email, subject, body);
Logger.log("File sent successfully!");
}
}
Sample Output:
Sample Form:
How to Install a Trigger Event:
In your form click the View in Sheets.
Click Extension > Apps Script.
Click on Triggers.
New Trigger then add the function to change the event type to On form Submit.
References: