Merge version_8 into main #22
104
src/app/api/contact/route.ts
Normal file
104
src/app/api/contact/route.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { name, email, phone, message } = await request.json();
|
||||
|
||||
// Validate required fields
|
||||
if (!name || !email || !message) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Missing required fields' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Email validation
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(email)) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Invalid email address' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Format the email content
|
||||
const emailContent = `
|
||||
New Contact Form Submission from Earl Boys Services Website
|
||||
|
||||
Name: ${name}
|
||||
Email: ${email}
|
||||
Phone: ${phone || 'Not provided'}
|
||||
|
||||
Message:
|
||||
${message}
|
||||
|
||||
---
|
||||
This message was sent from your website contact form.
|
||||
`;
|
||||
|
||||
// Send email notification (you'll need to configure your email service)
|
||||
// This is a placeholder for your email sending logic
|
||||
// You can use services like Nodemailer, SendGrid, AWS SES, etc.
|
||||
|
||||
// Example with a generic webhook or internal email service:
|
||||
const emailResponse = await sendEmailNotification({
|
||||
to: 'info@earlboysservices.com',
|
||||
subject: `New Contact Form Submission from ${name}`,
|
||||
text: emailContent,
|
||||
replyTo: email,
|
||||
});
|
||||
|
||||
if (!emailResponse.success) {
|
||||
console.error('Email sending failed:', emailResponse.error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to send message' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
// Return success response
|
||||
return NextResponse.json(
|
||||
{ message: 'Contact form submitted successfully' },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Contact form error:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Email notification function - implement based on your email service
|
||||
async function sendEmailNotification({
|
||||
to,
|
||||
subject,
|
||||
text,
|
||||
replyTo,
|
||||
}: {
|
||||
to: string;
|
||||
subject: string;
|
||||
text: string;
|
||||
replyTo: string;
|
||||
}): Promise<{ success: boolean; error?: string }> {
|
||||
try {
|
||||
// Placeholder for email service integration
|
||||
// Configure your email service here (SendGrid, AWS SES, Nodemailer, etc.)
|
||||
|
||||
// Example: Using fetch to call an external email service
|
||||
// const response = await fetch('YOUR_EMAIL_SERVICE_ENDPOINT', {
|
||||
// method: 'POST',
|
||||
// headers: { 'Content-Type': 'application/json' },
|
||||
// body: JSON.stringify({ to, subject, text, replyTo }),
|
||||
// });
|
||||
|
||||
// For now, return success (implement actual email service)
|
||||
console.log(`Email notification: ${subject} to ${to}`);
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Email notification error:', error);
|
||||
return { success: false, error: String(error) };
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import FeatureCardTen from "@/components/sections/feature/FeatureCardTen";
|
||||
import TestimonialCardTwelve from "@/components/sections/testimonial/TestimonialCardTwelve";
|
||||
import FaqDouble from "@/components/sections/faq/FaqDouble";
|
||||
import FooterBaseReveal from "@/components/sections/footer/FooterBaseReveal";
|
||||
import { Sparkles, CheckCircle, TrendingUp, Users } from "lucide-react";
|
||||
import { Sparkles, CheckCircle, TrendingUp, Users, Shield, Zap, Globe } from "lucide-react";
|
||||
|
||||
export default function Home() {
|
||||
const navItems = [
|
||||
|
||||
Reference in New Issue
Block a user