i’m getting recipient not defined yet i believe it has been done correctly I marked the issue in italic and underlined 13 lines down
import {sendEmail, sendEmailWithRecipient} from ‘backend/email’;
$w.onReady( function () {
$w(“#dataset1”).onAfterSave(sendFormData);
});
function sendFormData() {
const subject = New Employee Application ${$w("#input1").value}
;
const body = Type Here: ${$w("#input1").value} \rName: ${$w("#input1").value} \rPhone: ${$w("#input2").value} \rLocation: ${$w("#input3").value} \rJobSkills&Training: ${$w("#textBox1").value} \rResume: ${$w("#uploadButton1").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 = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
const sender = “mr-trim@live.ca”;
const recipient = “mr-trim@live.ca”;
return sendWithService(key, sender, recipient, subject, body);
}
export function sendEmailWithRecipient(subject, body, recipient) {
const key = “SG.Nntl_VUlSgWXBTQaLPZ8Ww.-_7BOPzBM6IN2ZJVrXFEJ-pRbewrzsCWd5bfTLl–m8”;
const sender = “mr-trim@live.ca”;
return sendWithService(key, sender, recipient, subject, body);
}
.js File: 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());