update doormile approach
This commit is contained in:
39
src/lib/contactForm.ts
Normal file
39
src/lib/contactForm.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user