# Sending an Email on Form Submission Help

**URL:** <https://forum.wixstudio.com/t/sending-an-email-on-form-submission-help/35772>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [August 2, 2021, 11:11pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-help/35772 "2021-08-02T23:11:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dragon13night](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/dragon13night/32/17347_2.png) [@dragon13night](https://forum.wixstudio.com/u/dragon13night)\
**Post date:** [August 2, 2021, 11:11pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-help/35772/1 "2021-08-02T23:11:54Z")

</div>

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](https://www.dragonnight.com.au/testimonials)” );  
}, 800 );  
}

The other parts of this  
[//email.jsw](https://email.jsw)  
import { sendWithService } from ‘backend/sendGrid’ ;  
export function sendEmail ( subject , body )  
{  
const key = “API KEY” ;  
const sender = “[dragon13night@hotmail.com](mailto:dragon13night@hotmail.com)” ;  
const recipient = “[dragon13night@hotmail.com](mailto:dragon13night@hotmail.com)” ;  
**return** sendWithService ( key , sender , recipient , subject , body );  
}

[//sendGrid.js](https://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](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 ());  
}

---

<div class="post-metadata">

**Author:** ![dragon13night](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/dragon13night/32/17347_2.png) [@dragon13night](https://forum.wixstudio.com/u/dragon13night)\
**Post date:** [August 3, 2021, 4:03am UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-help/35772/2 "2021-08-03T04:03:45Z")

</div>

I have no idea why its not working, i feel im going around in circles
