Merge version_12 into main #14
57
src/app/api/send-email/route.ts
Normal file
57
src/app/api/send-email/route.ts
Normal file
@@ -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 = `
|
||||
<h2>New Website Request</h2>
|
||||
<p><strong>Name:</strong> ${name}</p>
|
||||
<p><strong>Email:</strong> ${email}</p>
|
||||
<p><strong>Business Name:</strong> ${businessName}</p>
|
||||
<p><strong>Phone:</strong> ${phone}</p>
|
||||
<p><strong>Message:</strong></p>
|
||||
<p>${message.replace(/\n/g, '<br>')}</p>
|
||||
`;
|
||||
|
||||
// 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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1387,4 +1387,4 @@ export default function RootLayout({
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
</div>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user