Make this code better

Google Sheet auto response from third party email with attachment

New to coding. Pieced this together from a few sources. Was working fine until I tried to get it to send from a third party email instead of mine and tried to add an attachment file. Can someone show me what I am doing wrong and how to correct this?

untitled.php
function onFormSubmit(e) { var ownerMail = "tryouts@eclipseselect.org,"; var senderMail = e.values[9]; var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; var validMail = emailPattern.test(senderMail); var player = e.values[1]; var last = e.values[3]; var gender = e.values[4]; var level = e.values[5]; var dob = e.values[7]; var file = DriveApp.getFilesByName('TryoutRegistrationForm.pdf'); var emailBody = 'Dear '+last+' Family -<br><br>' +'Eclipse Select Soccer Club has received your on-line registration for an up coming tryout with our club.<br>' +'See the information below and let us know if anyting is incorrect:<br><br>' +'<br>' +'Player First Name: '+player+'<br>' +'Player Last Name: '+last+'<br>' +'Player Gender: '+gender+'<br>' +'Tryout Location, or Level player will attend: '+level+'<br>' +'Player Date of Birth: '+dob+'<br>' +'<br>' +'If any information is inaccurate please email:<br>' +'Tryouts@EclipseSelect.org<br>' +'<br>' +'We look forward to seeing you at our up coming tryouts.<br>' +'Please visit our website to download and complete necessary tryout documents prior to coming to a tryout.<br>' +'http://www.eclipseselect.org/<br>' +'<br><br>' +'Sincerely,<br><br>' +'Eclipse Select Soccer Club<br>' +'Dedicated to Family, Built on Tradition, Committed to Excellence<br>' if(validMail){ GmailApp.sendEmail(senderMail, 'Eclipse Select Soccer Club', '', {htmlBody:emailBody, bcc:ownerMail}) attachments: [file.next().getAs(MimeType.PDF)], name: 'Automatic Emailer Script' }; else { GmailApp.sendEmail(ownerMail, 'Invalid form submission', '', {htmlBody: 'Someone has submitted form with invalid email. Check it ' +'<a href="'+SpreadsheetApp.getActiveSpreadsheet().getUrl()+'">' +'here</a>'}); } }

Reactions 0 reactions

No reactions yet, be the first: comment or tweak the code

Comment on this code:

Please Login or Register to leave a comment.