# Sending an Email on Form Submission Using SendGrid Template

**URL:** <https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745>\
**Category:** Ask the community\
**Tags:** design, question, code\
**Created:** [January 30, 2019, 7:00pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745 "2019-01-30T19:00:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![aegrasty](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@aegrasty](https://forum.wixstudio.com/u/aegrasty)\
**Post date:** [January 30, 2019, 7:00pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745/1 "2019-01-30T19:00:55Z")

</div>

Hello everyone! I have been diving deeper into the wix-fetch API so that I can use 3rd party services in some of my website functionality. I have designed a landing page for a client and that will be used to capture referral form data. I have been able to leverage the Wix Code Tutorial: Sending an Email on Form Submission to successful setup API integration,

However, I would like to make the design a bit more professional that the plain-text option. I was thinking I could do this through Transactional Templates. I have followed the steps and within Sending Template Emails with SendGrid V3 but am still having trouble. Nothing occurs. No email is generated or sent. My code snippets are below. Can anyone spot what I am missing?

[//email.jsw](https://email.jsw)

```javascript
import {sendInstruction} from 'backend/sendGrid';

export function sendEmail(subject, body, Recipient) {
 const key = "XXXXXXXAPIKEYXXXXXXXXXXX";
 const sender = "recipientEmailHere";
 return sendInstruction(key, sender, Recipient, subject, body);
}

```

[//sendGrid.js](https://sendGrid.js)

```javascript
export function SendInstruction(key, sender, RecipientEmail, subject, body) {
 const url = "https://api.sendgrid.com/v3/mail/send";
 
 const MyHeaders = {
 "Authorization": "Bearer " + key,
 "Content-Type": "application/json"
  };
 const MyBody = {
 "personalizations": [{
 "to": [{
 "email": RecipientEmail
      }]
    }],
 "from": {
 "email": sender
    },
 "subject": subject,
 "content": [{
 "type": "text/html",
 "value": body
    }],
 "template_id" : "d-9ccb08ff65b3405b82f430ee3f6e5014"
  };

 return fetch(url, {
 "method": "POST",
 "headers": MyHeaders,
 "body": JSON.stringify(MyBody)
    })
    .then(Response => Response.text);   
}

```

Page Code

```javascript
import {sendEmail} from 'backend/email';

function SendClientEmail() {
const Subject = `New Submission from ${$w("#firstNameInput").value}`;
const body = `Name: ${$w("#firstNameInput").value}     
\rEmail: ${$w("#referralEmailInput").value}`;

const RecipientEmail = 'recipientEmail';

  sendEmail(Subject, body, RecipientEmail)
    .then(response => console.log(response)); 
}

```

There may be a lot of issues here but any assistance would be great!

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [January 31, 2019, 6:54am UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745/2 "2019-01-31T06:54:50Z")

</div>

Here are a couple of examples that will be helpful:

#### **Send Email with SendGrid NPM Interface**

[Send an email](https://www.wix.com/code/home/forum/wix-tips-and-updates/example-send-email-with-the-sendgrid-npm-interface) using the SendGrid NPM library.

#### **Send Email with SendGrid REST Interface**

[Send an email](https://www.wix.com/code/home/forum/wix-tips-and-updates/example-send-email-with-the-sendgrid-rest-interface) using the SendGrid REST API.

---

<div class="post-metadata">

**Author:** ![johnathonlynch](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/johnathonlynch/32/7404_2.png) [@johnathonlynch](https://forum.wixstudio.com/u/johnathonlynch)\
**Post date:** [February 6, 2019, 6:44pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745/3 "2019-02-06T18:44:23Z")

</div>

BUMP!  
Here trying to use a template with sendgrid as well, to no avail. Here’s hoping we find an answer!

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [February 9, 2019, 8:58pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745/4 "2019-02-09T20:58:43Z")

</div>

[https://support.totallycodable.com/en/article/send-a-template-email-using-sendgrid-npm-and-wix-code](https://support.totallycodable.com/en/article/send-a-template-email-using-sendgrid-npm-and-wix-code)

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [February 10, 2019, 11:52am UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745/5 "2019-02-10T11:52:46Z")

</div>

Thank you for sharing our tutorial article 😊

---

<div class="post-metadata">

**Author:** ![aegrasty](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@aegrasty](https://forum.wixstudio.com/u/aegrasty)\
**Post date:** [February 28, 2019, 6:12pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745/6 "2019-02-28T18:12:53Z")

</div>

@johnathonlynch I was able to get everything to work by following Nayeli’s tutorial.

---

<div class="post-metadata">

**Author:** ![callumsaffet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/callumsaffet/32/9350_2.png) [@callumsaffet](https://forum.wixstudio.com/u/callumsaffet)\
**Post date:** [July 15, 2019, 10:10pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745/7 "2019-07-15T22:10:06Z")

</div>

I’ve followed all the instructions and it doesn’t work. Please help.

---

<div class="post-metadata">

**Author:** ![tristan-breon-1](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/tristan-breon-1/32/2055_2.png) [@tristan-breon-1](https://forum.wixstudio.com/u/tristan-breon-1)\
**Post date:** [December 28, 2020, 10:31pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745/8 "2020-12-28T22:31:13Z")

</div>

It seems like it stopped working for a reason ! Any idea why ?

---

<div class="post-metadata">

**Author:** ![yuuktiyoga](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yuuktiyoga/32/27750_2.png) [@yuuktiyoga](https://forum.wixstudio.com/u/yuuktiyoga)\
**Post date:** [June 26, 2021, 12:47pm UTC](https://forum.wixstudio.com/t/sending-an-email-on-form-submission-using-sendgrid-template/12745/9 "2021-06-26T12:47:04Z")

</div>

I managed to send Sendgrid template variables, documentation here:

> **[Send mail with Sendgrid HTML templates after saving a form. Working! | Velo...](https://community.wix.com/velo/forum/coding-with-velo/send-mail-with-sendgrid-html-templates-after-saving-a-form-working)**
>
> Page Code:
> import { sendTemplateEmail } from 'backend/email'; 
> 
> function sendHTMLmail\_RequestReceived() { 
> const sender = "valid-sendgrid-account@yuuktiyoga.cl"; 
> const bcc = "fixed-reply-account@yuuktiyoga.cl"; 
> const recipient =...
