From 04c59f7d7a2ce2a33f08242611470c696ca67274 Mon Sep 17 00:00:00 2001 From: Daniel LaForce Date: Wed, 9 Apr 2025 17:38:13 -0600 Subject: [PATCH] Add contact form functionality and enhance logo styles --- functions/api/send-email.js | 54 +++++++++++++++++++++++++++++++++++ index.html | 6 ++-- resume.html | 8 +++--- script.js | 47 ++++++++++++++++++++---------- styles.css | 37 ++++++++++++++++++++++-- test-styles.css | 57 ------------------------------------- 6 files changed, 127 insertions(+), 82 deletions(-) create mode 100644 functions/api/send-email.js delete mode 100644 test-styles.css 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: ` +

New Contact Message

+

Name: ${name}

+

Email: ${email}

+

Message:
${message.replace(/\n/g, "
")}

+ `, + reply_to: [ + { + email, + name + } + ] + }) + }); + + if (!response.ok) { + console.error("MailerSend Error:", await response.json()); + return new Response(JSON.stringify({ error: "Failed to send email" }), { status: 500 }); + } + + return new Response(JSON.stringify({ success: true }), { status: 200 }); + + } catch (err) { + console.error("Unexpected Error:", err); + return new Response(JSON.stringify({ error: "Unexpected server error" }), { status: 500 }); + } +} diff --git a/index.html b/index.html index 35ca1dd..9908deb 100644 --- a/index.html +++ b/index.html @@ -25,7 +25,6 @@ - @@ -41,8 +40,7 @@