-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp_Script.html
More file actions
47 lines (39 loc) · 1.45 KB
/
App_Script.html
File metadata and controls
47 lines (39 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// --- COPY THIS INTO GOOGLE APPS SCRIPT ---
function doPost(e) {
try {
// 1. Get the active sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// 2. Extract data from the form submission
var data = e.parameter;
var timestamp = new Date();
// 3. Append data to the Google Sheet
sheet.appendRow([
timestamp,
data.name,
data.email,
data.location,
data.property_type,
data.bill,
data.message
]);
// 4. Send Email Notification
var emailBody = "New Form Submission:<br><br>" +
"<b>Name:</b> " + data.name + "<br>" +
"<b>Email:</b> " + data.email + "<br>" +
"<b>Location:</b> " + data.location + "<br>" +
"<b>Type:</b> " + data.property_type + "<br>" +
"<b>Bill:</b> " + data.bill + "<br>" +
"<b>Message:</b> " + data.message;
MailApp.sendEmail({
to: "gyanchandmaurya@gmail.com",
subject: "New Lead: " + data.name,
htmlBody: emailBody
});
// 5. Return success message
return ContentService.createTextOutput(JSON.stringify({ "result": "success" }))
.setMimeType(ContentService.MimeType.JSON);
} catch (error) {
return ContentService.createTextOutput(JSON.stringify({ "result": "error", "error": error.message }))
.setMimeType(ContentService.MimeType.JSON);
}
}