Hi,
I am having an issue with my code. I am able to submit a form and receive an email confirmation of user details. However, having an issue setting up my code in my email.JWS page for the user to receive a form submission confirmation . Here is my code, any help would be great! I currently use gmail to receive form submissions from users.
email.jsw
import {sendWithService} from ‘backend/sendGrid’;
export function sendEmail(subject, body) {
const key = “API KEY IS SET”;
const sender = “WHAT EMAIL DO I USE?”;
const recipient = “WHAT EMAIL DO I USE?”;
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = “API KET SET HERE”;
const sender = “WHAT EMAIL DO I USE?”;
return sendWithService(key, sender, recipient, subject, body);
}
sendGrid.js
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());
}
Contact page code
import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;
$w.onReady( function () {
$w(“#datasetContact”).onAfterSave(sendFormData);
});
function sendFormData() {
const subject = New Property Submission Form: ${$w("#iContactFirst").value}
;
const body = Name Property request Form: ${$w("#iContactFirst").value} \rFirst Name: ${$w("#iContactFirst").value} \rLast Name: ${$w("#iContactLast").value} \rPhone Number: ${$w("#iContactPhone").value} \rEmail: ${$w("#iContactEmail").value} \rMessage: ${$w("#iContactMessage").value} \rProp1: ${$w("#iContactProperties1").value} \rProp2: ${$w("#iContactProperties2").value}
;
const recipient = $w(“#iContactEmail”).value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response))