added contact form
This commit is contained in:
39
src/pages/api/send-message.ts
Normal file
39
src/pages/api/send-message.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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 <contactform@noelleparisdesign.com>', // Update to your domain once verified in Resend
|
||||
//to: 'github@juchatz.com',
|
||||
to: 'inquiries@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' } }
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user