Can anyone show me why my codes not working. I hereby paste
with my email.jsw, sendGrid.js and Event hander
//email.jsw import {sendWithService} from 'backend/sendGrid'; export function sendEmail(subject, body) { const key = "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"; const sender = "from.hl@framecount.com"; const recipient = "to.datacollection@mascusa.com"; return sendWithService(key, sender, recipient, subject, body); } export function sendEmailWithRecipient(subject, body, recipient) { const key = "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"; const sender = "from.hl@framecount.com"; 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()); }
######################################################################
import {sendEmail, sendEmailWithRecipient} from 'backend/email'; $w.onReady(function () { $w("#dataset8").onAfterSave(sendFormData); }); function sendFormData() { const subject = `Membership Application From ${$w("#input1").value}`; const body = `Name: ${$w("#input1").value} \rWhat Application: ${$w("#dropdown1").value} \rWhich Member: ${$w("#radioGroup1").value} \rEmail: ${$w("#input9").value}`; const recipient = $w("#input9").value; sendEmailWithRecipient(subject, body, recipient) .then(response => console.log(response)); }
These two examples you have sent are working fine but I am not sure whether it's useful to me.
I have a online form for visitors to fill it in and when submitted, all the info will be collected into the database.
And what I need is a email reminder from sendGrid to let me know I need to check the database.
Try one of these Sendgrid examples:
Send an email using the SendGrid NPM library.
Send an email using the SendGrid REST API.