From 74650a39b3efa9a3e3836cdedbfa54dc643a6cf0 Mon Sep 17 00:00:00 2001 From: nmemmert Date: Thu, 9 Apr 2026 15:48:40 -0400 Subject: [PATCH] Polish contact email subject and HTML layout --- server.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 9b65500..0c966cf 100644 --- a/server.js +++ b/server.js @@ -4,6 +4,15 @@ import path from 'node:path' import { fileURLToPath } from 'node:url' import { Resend } from 'resend' +function escapeHtml(value) { + return String(value) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, ''') +} + const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) const DATA_DIR = path.join(__dirname, 'data') @@ -95,13 +104,56 @@ app.post('/api/contact', contactRateLimit, async (req, res) => { return } + const trimmedName = name.trim() + const trimmedEmail = email.trim() + const trimmedMessage = message.trim() + const submittedAt = new Date().toLocaleString('en-US', { + dateStyle: 'medium', + timeStyle: 'short', + }) + const resend = new Resend(process.env.RESEND_API_KEY) const { error } = await resend.emails.send({ from: process.env.RESEND_FROM ?? 'Verse by Verse ', to: [process.env.RESEND_TO ?? 'vbvwithnate@outlook.com'], - replyTo: email.trim(), - subject: `New message from Verse by Verse website — ${name.trim()}`, - text: `Name: ${name.trim()}\nEmail: ${email.trim()}\n\nMessage:\n${message.trim()}`, + replyTo: trimmedEmail, + subject: `Verse by Verse contact form: ${trimmedName}`, + text: + `New contact form submission\n\n` + + `Name: ${trimmedName}\n` + + `Email: ${trimmedEmail}\n` + + `Submitted: ${submittedAt}\n\n` + + `Message:\n${trimmedMessage}`, + html: + `
` + + `
` + + `
` + + `
Verse by Verse with Nate
` + + `

New Contact Form Submission

` + + `
` + + `
` + + `

A new message was sent from the website contact form. Reply directly to this email to respond to ${escapeHtml(trimmedName)}.

` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `` + + `
Name${escapeHtml(trimmedName)}
Email${escapeHtml(trimmedEmail)}
Submitted${escapeHtml(submittedAt)}
` + + `
` + + `
Message
` + + `
${escapeHtml(trimmedMessage)}
` + + `
` + + `
` + + `
` + + `
`, }) if (error) throw error