Contact Forms and Sendgrid working on local PC not on Cloudflare Pages

I'm using Sendgrid for my contact forms with cloudflare.

It's working fine on my local computer but when I push it to the Cloudflare Pages it's not working.

Can you please let me know if I have to do any additional configurations in Cloudflare Pages?

I'm using the following code using POST method:

async function sendMail(email, name, message)
{
    const res = await fetch('https://api.sendgrid.com/v3/mail/send',
    {
        method: 'POST',
        headers : {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + SENDGRID_API
      },
      body:'{"personalizations": [{"to": [{"email": "email@addressto.com"}]}],"from": {"email": "email@addressfrom.com"}, "reply_to": {"email": "'+email+'"}, "subject": "Contact from website' +name+'"  ,"content": [{"type": "text/plain", "value": " '+message+'"}]}'

    });

    return {success: true, results: res};
}
Was this page helpful?