Resend is a simple, fast, and free email API service designed to make sending transactional emails, such as contact form submissions, incredibly easy. It allows you to quickly send emails without the need to worry about setting up or maintaining your own email servers.
- 100 emails per day (Daily Limit)
- 3,000 emails per month (Monthly Limit)
- 4 sender addresses available for use
- No credit card required to get started
This repository contains a serverless function that processes contact form submissions. It validates the input data and sends an email via Resend, making it a simple, efficient, and cost-free solution for handling contact forms.
This Cloudflare Worker:
- Accepts
POST
requests with form data in JSON format. - Validates the provided input (name, email, phone, subject, message).
- Sends an email via Resend API.
- Returns a JSON response confirming success or showing validation errors.
- Log in to Cloudflare Dashboard
- Navigate to Workers & Pages → Create a Service
- Choose HTTP Handler
- Select Quick Edit
Cloudflare Workers allow environment variables to be configured in the dashboard. Go to Settings → Variables and add:
Variable Name | Description |
---|---|
RESEND_API_KEY |
Your Resend API key |
RESEND_FROM |
Sender email address |
RESEND_TO |
Recipient email address |
- Copy and paste the Worker code into Cloudflare’s editor.
- Click Save and Deploy.
You can test the deployed Worker using cURL, JavaScript fetch API, or Postman.
curl -X POST https://your-worker-subdomain.workers.dev/contact-form \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "johndoe@example.com",
"phone": "+1234567890",
"subject": "Test Message",
"message": "Hello, this is a test message sent via Cloudflare Worker!"
}'
async function sendFormData() {
const response = await fetch("https://your-worker-subdomain.workers.dev/contact-form", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: "John Doe",
email: "johndoe@example.com",
phone: "+1234567890",
subject: "Test Message",
message: "Hello, this is a test message sent via Cloudflare Worker!"
}),
});
const result = await response.json();
console.log(result);
}
sendFormData();
{
"status": "success",
"message": "Email sent successfully!"
}
{
"status": "error",
"message": "Validation failed",
"data": {
"fields": {
"email": "Invalid email format"
}
}
}
{
"status": "error",
"message": "Service error"
}
You can find the full code in this repository. The worker is already set up and ready to deploy with Cloudflare Workers and Resend.
This Cloudflare Worker provides an easy, serverless solution for handling contact form submissions and sending emails via Resend. No backend setup is needed—just deploy the worker and configure your API keys.
🚀 Start using Resend for free and integrate it with Cloudflare Workers today!