I am trying to implement the SendEmail on Submit of a form. After changing the code to fit my needs I am getting Errors on the Page code for both the JWS and the JS. If you click the red dot it shows “sendEmailWithRecipient” is undefined" and “sendEmail is undefined”. Both ARE shown in the “backend” section with no errors. Here is the code:
Page Code:
//comments
$w.onReady(function () {
//TODO: write your page related code here…
});
function sendFormData() {
const subject = Registry History Request For Dash #${$w("#input3").value}
;
const body = May I Please Have Access To The History For Dash#: ${$w("#input3").value} \rName: ${$w("#input1").value} \rEmail: ${$w("#input2").value}
;
const recipient = $w(“#input1”).value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
import {sendWithService} from ‘backend/sendGrid’;
export function sendEmail(subject, body) {
const key = “< MY KEY>”;
const sender = “cwvega76@gmail.com”;
const recipient = “cwvega76@gmail.com”;
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = “< MY KEY>”;
const sender = “cwvega76@gmail.com”;
return sendWithService(key, sender, recipient, subject, body);
}
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());
}