import type { APIRoute } from 'astro'; import { Resend } from 'resend'; const resend = new Resend(import.meta.env.RESEND_API_KEY); export const POST: APIRoute = async ({ request }) => { try { const data = await request.json(); const { name, email, phone, message } = data; if (!name || !email || !message) { return new Response( JSON.stringify({ message: 'Missing required fields' }), { status: 400, headers: { 'Content-Type': 'application/json' } } ); } // Send email via Resend await resend.emails.send({ from: 'Noelle Paris Design Contact Form ', // Update to your domain once verified in Resend //to: 'github@juchatz.com', to: 'noelle@noelleparisdesign.com', replyTo: email, subject: `New Inquiry from ${name}`, text: `Name: ${name}\nEmail: ${email}\nPhone: ${phone || 'N/A'}\n\nMessage:\n${message}`, }); return new Response( JSON.stringify({ message: 'Message sent successfully' }), { status: 200, headers: { 'Content-Type': 'application/json' } } ); } catch (error) { console.error('Email error:', error); return new Response( JSON.stringify({ message: 'Error sending email' }), { status: 500, headers: { 'Content-Type': 'application/json' } } ); } };