feat: add resend for email

fix: nebual minified react error
This commit is contained in:
jwinterm
2026-01-29 11:23:54 -05:00
parent b80723cd28
commit 2838133681
5 changed files with 95 additions and 50 deletions
+30 -10
View File
@@ -1,7 +1,10 @@
'use server';
import { z } from 'zod';
import { verifyTurnstile } from '@/lib/turnstile'; // Helper to call Cloudflare API
import { Resend } from 'resend';
import { verifyTurnstile } from '@/lib/turnstile';
const resend = new Resend(process.env.RESEND_API_KEY);
const ContactSchema = z.object({
name: z.string().min(2, "Name is too short"),
@@ -12,7 +15,7 @@ const ContactSchema = z.object({
export async function submitContactForm(prevState: any, formData: FormData) {
const rawData = Object.fromEntries(formData.entries());
// 1. Zod Validation
const validated = ContactSchema.safeParse(rawData);
if (!validated.success) {
@@ -25,17 +28,34 @@ export async function submitContactForm(prevState: any, formData: FormData) {
return { success: false, message: "Security check failed. Please refresh." };
}
// 3. Send to Backend (or Email)
// 3. Send email via Resend
try {
// TODO: Connect to email service or CMS
console.log("Form submitted:", validated.data);
// Simulating success for now
await new Promise(resolve => setTimeout(resolve, 500));
const { name, email, message } = validated.data;
const contactEmail = process.env.CONTACT_EMAIL || 'sales@such.software';
const { error } = await resend.emails.send({
from: 'Such Software <noreply@such.software>',
to: contactEmail,
replyTo: email,
subject: `New inquiry from ${name}`,
text: `Name: ${name}\nEmail: ${email}\n\nMessage:\n${message}`,
html: `
<h2>New Project Inquiry</h2>
<p><strong>Name:</strong> ${name}</p>
<p><strong>Email:</strong> <a href="mailto:${email}">${email}</a></p>
<h3>Message:</h3>
<p>${message.replace(/\n/g, '<br>')}</p>
`,
});
if (error) {
console.error('Resend error:', error);
return { success: false, message: "Failed to send message. Please try again." };
}
return { success: true, message: "Request received. We will be in touch shortly." };
} catch (e) {
console.error(e);
console.error('Email error:', e);
return { success: false, message: "System error. Please contact us via email." };
}
}