Hi everyone and thanks in advance for any help offered
i have a form - feeds into a data base
i need an email sent to me and an auto responder email sent to the person who filled the form out
Ive followed the instructions here
i have it sending form inputs to me no problem
however when I’ve added additional code to also send out auto responder message - it stoped sending the form inputs to me. But does send out the auto responder with inputs ( to be changed to html email later)
import {sendWithService} from ‘backend/sendGrid’;
export function sendEmail(subject, body) {
const key = “hidden”;
const sender = “hidden”;
const recipient = “hidden”;
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = “hidden”;
const sender = “hidden”;
return sendWithService(key, sender, recipient, subject, body);
}
//front end event handler
import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;
$w.onReady(function () {
$w(“#dataset1”).onAfterSave(sendFormData);
});
function sendFormData() {
const subject = New Submission from ${$w("#inputName").value}
;
const body = Name: ${$w("#inputName").value} \rEmail: ${$w("#inputEmail").value} \rPhone: ${$w("#inputTelephone").value} \rChoice: ${$w("#InputChoice").value}
;
const recipient = $w(“#inputEmail”).value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
}
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());
}