# Wix Issue with SendGrid

**URL:** <https://forum.wixstudio.com/t/wix-issue-with-sendgrid/51855>\
**Category:** Ask the community\
**Tags:** wix-studio, code\
**Created:** [August 25, 2023, 8:11am UTC](https://forum.wixstudio.com/t/wix-issue-with-sendgrid/51855 "2023-08-25T08:11:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![starblaster124](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/starblaster124/32/81190_2.png) [@starblaster124](https://forum.wixstudio.com/u/starblaster124)\
**Post date:** [August 25, 2023, 8:11am UTC](https://forum.wixstudio.com/t/wix-issue-with-sendgrid/51855/1 "2023-08-25T08:11:13Z")

</div>

I’m trying to use Wix to send a dynamic email template through SendGrid upon the user clicking a button, but I keep getting a couple of error messages and am wondering how I can fix these. The first error message I see is that there is an invalid character in the header, and the second error message I see is in Chrome Dev Tools, it shows that access is being blocked because of CORS. Here are my error messages and the code.

 ![Screen Shot 2023-08-25 at 12.55.24 AM](https://us1.discourse-cdn.com/wix/original/3X/8/a/8aeeace8539d193a03425dcbf60cbe373c52137d.png)  
 ![Screen Shot 2023-08-25 at 12.56.15 AM](https://us1.discourse-cdn.com/wix/original/3X/e/b/eb9739f7b3e6f03a455038f57a65b6e1ce02aec6.png)

Page Code: I know for a fact all my variables are getting initialized and saved fine.

```javascript
import {sendEmail} from 'backend/sendGrid2.jsw'

$w('#button8').onClick(async () => {
	let result = sendEmail(body, parentEmail, firstName, logoLink2, level, impression, strengths, growthAreas, socialEmotionalClassReadiness, brochureLink, levelLink, classLink, siteAddress, sitePhone, siteEmail, facebook, linkedin, instagram, classTimings);

}

```

Backend:  
sendGrid2.jsw

```javascript
import {fetch} from 'wix-fetch'; 
import { sendEmailTemplate } from '@velo/sendgrid-templates-backend'
import wixSecretsBackend from 'wix-secrets-backend';

export async function sendEmail(body, parentEmail, firstName, lastName, logoLink2, level, impression, strengths, growthAreas, socialEmotionalClassReadiness, brochureLink, levelLink, classLink, siteAddress, sitePhone, siteEmail, facebook, linkedin, instagram, classTimings) {
	const url = "https://api.sendgrid.com/v3/mail/send";

    const sendGridSecret = JSON.parse(await wixSecretsBackend.getSecret('sendGridSecret'));
    const key = sendGridSecret.key;
    const senderEmail = sendGridSecret.senderEmail;
		
	const MyHeaders = {
		"Authorization": "Bearer " + key,
		"content-type": "application/json"
	};
	const MyBody = {
		 "personalizations": [
    {
      "to": [
        {
          "email": parentEmail,
          "name": firstName
        }
      ],
	  "dynamic_template_data": [
		{
			"firstName": firstName,
			"logoLink2": logoLink2,
			"level": level,
			"impression": impression,
			"strengths": strengths,
			"growthAreas": growthAreas,
			"socialEmotionalClassReadiness": socialEmotionalClassReadiness,
			"brochureLink": brochureLink,
			"levelLink": levelLink,
			"classLink": classLink,
			"siteAddress": siteAddress,
			"sitePhone": sitePhone,
			"siteEmail": siteEmail,
			"facebook": facebook,
			"linkedin": linkedin,
			"instagram": instagram,
			"classTimings": classTimings
		}
	  ]
    }
  ],
  "from": {
    "email": senderEmail,
    "name": "Example Order Confirmation"
    },
  "subject": "Free Trial Assessment for " + firstName + " " + lastName,
  "content": [
    {
      "type": "text/html",
      "value": body
    }
    ],
		"template_id" : "d-3796a64d9b764b1db176cc8cbc348492"
	};

	sendEmailTemplate(MyBody);	
}

```

How would I go about fixing these errors?

---

<div class="post-metadata">

**Author:** ![noahlovell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/noahlovell/32/118920_2.png) [@noahlovell](https://forum.wixstudio.com/u/noahlovell)\
**Post date:** [August 29, 2023, 4:40pm UTC](https://forum.wixstudio.com/t/wix-issue-with-sendgrid/51855/2 "2023-08-29T16:40:59Z")

</div>

If you haven’t already, I’d check out the tutorial we have about sending emails with SendGrid - [Send Emails Using the SendGrid npm Package](https://dev.wix.com/docs/develop-websites/articles/getting-started/code-tutorials/send-emails-using-the-send-grid-npm-package)

There seems to be differences in the tutorial code and your code that seems to be causing the issues
