export const prerender = false;
import type { APIRoute } from "astro";
import * as postmark from "postmark";
import mjml2html from "mjml";
export const POST: APIRoute = async ({ request, redirect }) => {
const client = new postmark.ServerClient(import.meta.env.POSTMARK_TOKEN);
const data = await request.json();
const location = data.location;
const deliveryZip = data.deliveryZip;
const firstName = data.firstName;
const lastName = data.lastName;
const email = data.email;
const phone = data.phone;
const message = data.message;
// Validate required fields
status: "400 Bad Request",
message: "Email and phone are required fields.",
// Prepare email content for BREM
const { html: emailBody } = mjml2html(`
<mj-body background-color="#f4f4f4" font-family="Arial, sans-serif">
<mj-section background-color="#ffffff" padding-top="20px" padding-bottom="20px">
<mj-image src="https://bremstorage.com/assets/images/logo.png" alt="BREM Logo" width="150px" align="center" />
<mj-divider border-color="#dddddd" border-width="1px" />
<mj-section background-color="#ffffff" padding="30px">
<mj-text font-size="22px" color="#333333" font-weight="bold" align="center">
Thank you for contacting BREM Storage Solutions!
<mj-text font-size="16px" color="#555555" line-height="1.6" align="center">
Hi ${firstName} ${lastName},<br/>
We’ve received your inquiry, and we’re excited to assist you. Here are the details you submitted:
<mj-divider border-color="#dddddd" border-width="1px" />
<mj-text font-size="16px" color="#333333" line-height="1.6">
<strong>Email:</strong> ${email}<br/>
<strong>Phone:</strong> ${phone}<br/>
<strong>Location:</strong> ${location}<br/>
<strong>Delivery Zip:</strong> ${deliveryZip}
${message ? `<strong>Message:</strong> ${message}` : ''}
<mj-text font-size="16px" color="#555555" line-height="1.6" align="center">
A member of our team will contact you soon. Thank you for choosing BREM Storage Solutions!
From: "support@bremstorage.com",
Subject: "BREM Storage Solutions Inquiry",
MessageStream: "outbound",
console.error("Error sending email:", error);
status: "500 Internal Server Error",
message: "An error occurred while sending the email.",
// Redirect to the thank-you page
let redirectUrl = "/thank-you?";
return redirect(redirectUrl, 302);