53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
"use server";
|
|
|
|
import { sendEmail } from "../lib/mail/mailer";
|
|
import {
|
|
getInquiryEmailHtml,
|
|
getConfirmationEmailHtml,
|
|
} from "../components/ContactForm/EmailTemplates";
|
|
|
|
export async function sendContactInquiry(data: {
|
|
name: string;
|
|
email: string;
|
|
phone?: string;
|
|
role?: string;
|
|
companyName: string;
|
|
projectType: string;
|
|
deadline?: string;
|
|
message: string;
|
|
isFreeText: boolean;
|
|
config?: any;
|
|
}) {
|
|
try {
|
|
// Payload removed, directly send emails
|
|
// 2. Send Inquiry to Marc
|
|
const inquiryResult = await sendEmail({
|
|
subject: `[PROJEKT] ${data.isFreeText ? "DIREKTANFRAGE" : "KONFIGURATION"}: ${data.companyName || data.name}`,
|
|
html: getInquiryEmailHtml(data),
|
|
replyTo: data.email,
|
|
});
|
|
|
|
if (!inquiryResult.success) {
|
|
throw new Error(inquiryResult.error);
|
|
}
|
|
|
|
// 2. Send Confirmation to Customer
|
|
await sendEmail({
|
|
to: data.email,
|
|
subject: `Kopie deiner Anfrage: ${data.companyName || "mintel.me"}`,
|
|
html: getConfirmationEmailHtml(data),
|
|
});
|
|
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error("Server Action Error:", error);
|
|
return {
|
|
success: false,
|
|
error:
|
|
error instanceof Error
|
|
? error.message
|
|
: "Unknown error during submission",
|
|
};
|
|
}
|
|
}
|