diff --git a/functions/api/send-email.js b/functions/api/send-email.js new file mode 100644 index 0000000..7e01786 --- /dev/null +++ b/functions/api/send-email.js @@ -0,0 +1,54 @@ +import { Resend } from 'resend'; + +/** + * Cloudflare Pages Function - /api/send-email + */ +export async function onRequestPost(context) { + const { name, email, subject, message } = await context.request.json(); + + try { + 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: "daniel@laforceit.com", + name: "Daniel LaForce" + }, + to: [ + { + email: "daniel@laforceit.com", + name: "Daniel LaForce" + } + ], + subject: `[Argobox] ${subject}`, + html: ` +
Name: ${name}
+Email: ${email}
+Message:
${message.replace(/\n/g, "
")}