diff --git a/src/app/api/send-email/route.ts b/src/app/api/send-email/route.ts new file mode 100644 index 0000000..de7ac60 --- /dev/null +++ b/src/app/api/send-email/route.ts @@ -0,0 +1,57 @@ +import { NextRequest, NextResponse } from 'next/server'; +import nodemailer from 'nodemailer'; + +const transporter = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: process.env.EMAIL_USER, + pass: process.env.EMAIL_PASSWORD, + }, +}); + +export async function POST(request: NextRequest) { + try { + const { to, subject, name, email, businessName, phone, message } = await request.json(); + + // Validate required fields + if (!to || !subject || !name || !email || !businessName || !phone || !message) { + return NextResponse.json( + { error: 'Missing required fields' }, + { status: 400 } + ); + } + + // Create email body + const emailBody = ` +

New Website Request

+

Name: ${name}

+

Email: ${email}

+

Business Name: ${businessName}

+

Phone: ${phone}

+

Message:

+

${message.replace(/\n/g, '
')}

+ `; + + // Send email + const mailOptions = { + from: process.env.EMAIL_USER, + to: to, + subject: subject, + html: emailBody, + replyTo: email, + }; + + await transporter.sendMail(mailOptions); + + return NextResponse.json( + { success: true, message: 'Email sent successfully' }, + { status: 200 } + ); + } catch (error) { + console.error('Email sending error:', error); + return NextResponse.json( + { error: 'Failed to send email' }, + { status: 500 } + ); + } +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index a7c1f20..9d8fd84 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1387,4 +1387,4 @@ export default function RootLayout({ ); -} \ No newline at end of file +} diff --git a/src/app/page.tsx b/src/app/page.tsx index afed2b2..62c11f9 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -30,18 +30,17 @@ export default function LandingPage() { setError(""); try { - // Send email using Formspree - const response = await fetch("https://formspree.io/f/mpwazqqq", { + // Send email using EmailJS or direct backend call + const response = await fetch("/api/send-email", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ - name: formData.fullName, + to: "CoreScale.co@gmail.com", subject: "New Website Request – CoreScale", name: formData.fullName, email: formData.email, businessName: formData.businessName, phone: formData.phone, - message: formData.message, - _subject: "New Website Request – CoreScale", _reply_to: formData.email + message: formData.message }) }); @@ -368,4 +367,4 @@ export default function LandingPage() { ); -} \ No newline at end of file +}