Now I know there is a actical on this. Which I have lost count the amout of times I have read it. I have also watch the video from wix training academy as well. I got it to work once and that was it. Its stop working and I dont know where the problem is.
AIM: to get a email from my website saying someone has filled out the testimonal lightbox and what it says.
This is on my lightbox - which they fill out and leave a testimonial
import {sendEmail} from 'backend/email'; $w.onReady(function () { $w("#dataset1").onAfterSave(sendFormData); }); function sendFormData() { const subject = `Testimonioal was posted ${$w("#input1").value}`; const body = `Feedback was left on website: ${$w("#input1").value} \rName: ${$w("#input1").value} \rConractNumber: ${$w("#input3").value} \rService: ${$w("#dropdown1").value} \rEmail: ${$w("#input2").value} \rRating: ${$w("#ratingsInput1").value} \rTestimonial: ${$w("#textBox1").value}`; sendEmail(subject, body) .then(response => console.log(response)); } import wixLocation from 'wix-location'; export function button2_click(event) {$w('#dataset1').save(); setTimeout(() => { wixLocation.to("https://www.dragonnight.com.au/testimonials"); }, 800); }
The other parts of this
//email.jsw
import {sendWithService} from 'backend/sendGrid';
export function sendEmail(subject, body)
{
const key = "API KEY";
const sender = "dragon13night@hotmail.com";
const recipient = "dragon13night@hotmail.com";
return sendWithService(key, sender, recipient, subject, body);
}
//sendGrid.js
import {fetch} from 'wix-fetch';
export function sendWithService (APIKey, Sender, Recipient, Subject, Body)
{
const URL = "https://api.sendgrid.com/api/mail.send.json";
const Headers = {"Authorization":"Bearer " + APIKey, "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());
}
I have no idea why its not working, i feel im going around in circles