40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import emailjs from "@emailjs/browser";
|
|
|
|
interface ContactFormData {
|
|
fullName: string;
|
|
email: string;
|
|
subject: string;
|
|
message: string;
|
|
}
|
|
|
|
export async function submitContactForm(data: ContactFormData) {
|
|
const serviceId = process.env.NEXT_PUBLIC_EMAILJS_SERVICE_ID;
|
|
const templateId = process.env.NEXT_PUBLIC_EMAILJS_TEMPLATE_ID;
|
|
const publicKey = process.env.NEXT_PUBLIC_EMAILJS_PUBLIC_KEY;
|
|
|
|
if (!serviceId || !templateId || !publicKey) {
|
|
console.warn("EmailJS credentials are not configured. Falling back to mock success.");
|
|
// Simulate network delay
|
|
await new Promise((resolve) => setTimeout(resolve, 800));
|
|
return { success: true, mock: true };
|
|
}
|
|
|
|
try {
|
|
await emailjs.send(
|
|
serviceId,
|
|
templateId,
|
|
{
|
|
name: data.fullName,
|
|
email: data.email,
|
|
subject: data.subject,
|
|
message: data.message,
|
|
},
|
|
publicKey
|
|
);
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error("EmailJS sending failed:", error);
|
|
throw error;
|
|
}
|
|
}
|