```javascript
function doPost(e) {
try {
// Get the spreadsheet connected to this Apps Script
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// Get the Responses sheet
var sheet = spreadsheet.getSheetByName("Responses");
// Check that the sheet exists
if (!sheet) {
throw new Error("The sheet named 'Responses' was not found.");
}
// Collect submitted information
var fullName = e.parameter.fullName || "";
var whatsapp = e.parameter.whatsapp || "";
var email = e.parameter.email || "";
var consent = e.parameter.consent || "";
// Record the information in Google Sheet
sheet.appendRow([
new Date(),
fullName,
whatsapp,
email,
consent
]);
// ==============================
// EMAIL NOTIFICATION
// ==============================
var notificationEmail = "latunde247@gmail.com";
var subject = "New NYSC Update Broadcast Registration";
var message =
"A new person has joined the NYSC Update Broadcast List.\n\n" +
"Full Name: " + fullName + "\n" +
"WhatsApp Number: " + whatsapp + "\n" +
"Email Address: " + email + "\n" +
"Consent: " + consent + "\n" +
"Date & Time: " + new Date() + "\n\n" +
"This registration was submitted through the Expy Multimedia website.";
MailApp.sendEmail(
notificationEmail,
subject,
message
);
// ==============================
// SUCCESS RESPONSE
// ==============================
return HtmlService.createHtmlOutput(
'' +
'' +
'' +
'' +
'' +
'
Registration Successful!
' + 'Thank you for joining the Expy Multimedia NYSC Update Broadcast List.
' + '' + '' ); } catch (error) { // Record error in Apps Script logs console.log(error); return HtmlService.createHtmlOutput( '' + '' + 'Submission Error
' + 'We could not process your registration.
' + 'Please try again later.
' + '' + '' ); } } ```

Post a Comment