So I created a custom form (not a wix form) using user-inputs and finalized with a submit button.
email.jsw backend file:
import {sendWithService} from ‘database/ServiceForms’;
export function sendEmail(subject, body) {
const key = “…”;
const sender = “zaksauve@gmail.com”;
const recipient = “zaksauve@gmail.com”;
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = “…”;
const sender = “zaksauve@gmail.com”;
return sendWithService(key, sender, recipient, subject, body);
}
sendGrid.js backend file
import {fetch} from ‘wix-fetch’;
export function sendWithService(key, sender, recipient, subject, body) {
const url = “https://api.sendgrid.com/api/mail.send.json”;
const headers = {
“Authorization”: "Bearer " + key,
“Content-Type”: “application/x-www-form-urlencoded”
};
const data = from =${sender}&to=${recipient}&subject=${subject}&text=${body}
;
const request = {
“method”: “post”,
“headers”: headers,
“body”: data
};
return fetch(url, request)
.then(response => response.json());
}
Page file:
import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;
$w.onReady( function () {
$w(“#dataset1”).onAfterSave(sendFormData);
});
function sendFormData() {
const subject = Quote For Services ${$w("#input1").value}
;
const body = For: ${$w("#input1").value} \rName: ${$w("#input1").value} \rPhone Number: ${$w("#input2").value} \rEmail: ${$w("#input3").value} \rEvent Location: ${$w("#input4").value} \rDate of Event: ${$w("#datePicker1").value} \rComments: ${$w("#textBox1").value} \rGames: ${$w("#checkboxGroup1").value} \rHouses/Inflatables: ${$w("#checkboxGroup3").value} \rInstant Arcade: ${$w("#checkbox1").value}
;
const recipient = $w(“#input3”).value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
WEBSITE: https://info160562.wixsite.com/gotgamerentals
The database receives the input on SUBMIT. I don’t receive the email though.
Any suggestions?
THANK YOU!