/** * Cloudflare Pages Function - /api/send-email */ export async function onRequestPost(context) { const { name, email, subject, message } = await context.request.json(); try { // Check if API key is configured if (!context.env.MAILERSEND_API_KEY) { throw new Error('MailerSend API key is not configured'); } console.log('Attempting to send email with MailerSend...'); const response = await fetch("https://api.mailersend.com/v1/email", { method: "POST", headers: { Authorization: "Bearer " + context.env.MAILERSEND_API_KEY, "Content-Type": "application/json" }, body: JSON.stringify({ from: { email: email, name: name }, to: [ { email: "upwork@example.com", name: "Contact Form" } ], subject: `LaForceIT Contact Form: ${subject}`, html: `
Name: ${name}
Email: ${email}
Message:
${message.replace(/\n/g, "
")}