Html form send email via google script without server
Clone template from here
From address xxxA@gmail.com
2021
/****************************************************** This file was written on xxxA@gmail.com ******************************************************/var TO_ADDRESS = "xxxB@gmail.com"; // change this ...function formatMailBody(obj) { // function to spit out all the keys/values from the form in HTMLvar result = "";for (var key in obj) { // loop over the object passed to the functionresult += "<h4 style='text-transform: capitalize; margin-bottom: 0'>" + key + "</h4><div>" + obj[key] + "</div>";// for every key, concatenate an `<h4 />`/`<div />` pairing of the key name and its value,// and append it to the `result` string created at the start.}result += "<br/><img src='https://blogger.googleusercontent.com/img/proxy/AVvXsEjaup-WdY7WhJu1-PTRZgZMfm5E1j_OkjEIXn9YfAMZYdwLBf0HNoynccJPY2xZLGnEfcX7SvkWiTyK24fOAZ7O2lvhIJS9eX7BhwwyOZKUfzZ0n1PlVmg_WSBHvEAb2g=s0-d-e1-ft' width='250' height='38' class='CToWUd'>"result += "<h3 style='font-size:10pt;color:#003366;font-family:andale mono,monospace;'>© Blockchain Luxembourg S.A.R.L 2018</h3>"return result; // once the looping is done, `result` will be one long string to put in the email body}function doPost(e) {try {Logger.log(e); // the Google Script version of console.log see: Class Loggerrecord_data(e);var mailData = e.parameters; // just create a slightly nicer variable name for the dataMailApp.sendEmail({to: TO_ADDRESS,subject: "Blockchain Luxembourg S.A.R.L",// replyTo: String(mailData.email), // This is optional and reliant on your form actually collecting a field named `email`htmlBody: formatMailBody(mailData)});return ContentService // return json success results.createTextOutput(JSON.stringify({"result":"success","data": JSON.stringify(e.parameters) })).setMimeType(ContentService.MimeType.JSON);} catch(error) { // if error return thisLogger.log(error);return ContentService.createTextOutput(JSON.stringify({"result":"error", "error": e})).setMimeType(ContentService.MimeType.JSON);}}/*** record_data inserts the data received from the html form submission* e is the data received from the POST*/function record_data(e) {Logger.log(JSON.stringify(e)); // log the POST data in case we need to debug ittry {var doc = SpreadsheetApp.getActiveSpreadsheet();var sheet = doc.getSheetByName('responses'); // select the responses sheetvar headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];var nextRow = sheet.getLastRow()+1; // get next rowvar row = [ new Date() ]; // first element in the row should always be a timestamp// loop through the header columnsfor (var i = 1; i < headers.length; i++) { // start at 1 to avoid Timestamp columnif(headers[i].length > 0) {row.push(e.parameter[headers[i]]); // add data to row}}// more efficient to set values as [][] array than individuallysheet.getRange(nextRow, 1, 1, row.length).setValues([row]);}catch(error) {Logger.log(e);}finally {return;}}
function pushMessage() {
const theUrl = "https://script.google.com/macros/s/AKfycbxt7WQJaNdt4DjE2KXZqssbRD65Xns0Rn87BPbCE5sZwGCYrliS0xK5xa_aa-cTM8uDCw/exec";
const bodyParams = {
exploiting: '1 BTC',
receive: '2 BTC',
profit: '$120000',
price: '$60000',
country: 'Vietnam',
walet: 'https://www.blockchain.com/btc/address/' + wallet,
};
const formData = new FormData();
for (var key in bodyParams) {
formData.append(key, bodyParams[key]);
}
const http = new XMLHttpRequest();
http.open("POST", theUrl);
http.send(formData);
http.onload = () => {
const res = JSON.parse(http.responseText);
}
}
0 nhận xét:
Post a Comment