export const dynamic = 'force-dynamic' import { redirect } from 'next/navigation'; import nodemailer from 'nodemailer'; import sanitizeHtml from 'sanitize-html'; import { Container } from '@/components/Container' export default async function Page({ searchParams }) { const firstName = searchParams['first-name']; const lastName = searchParams['last-name']; const hostName = searchParams['host-name']; const email = searchParams['email']; const message = searchParams['message']; const submitted = firstName || lastName || email || message || hostName; const valid = submitted && firstName && lastName && email && message && hostName; const validHostName = valid && (hostName.toLowerCase().replaceAll(' ', '') === 'thomashintz' || hostName.toLowerCase().replaceAll(' ', '') === 'thomas' || hostName.toLowerCase().replaceAll(' ', '') === 'hintz'); let emailSentSuccessfully = false; if (valid && validHostName) { const transporter = nodemailer.createTransport({ host: process.env.CONTACT_HOST, port: 587, secure: false, // true for 465, false for other ports auth: { user: process.env.CONTACT_USER, pass: process.env.CONTACT_PASSWORD, }, }); // send mail with defined transport object await transporter.sendMail({ from: `"${firstName} ${lastName}" <${process.env.CONTACT_FROM_ADDRESS}>`, replyTo: `"${firstName} ${lastName}" <${email}>`, to: process.env.CONTACT_TO_ADDRESS, subject: "The React Show - Form Submission", text: message, html: sanitizeHtml(message, { allowedTags: [], allowedAttributes: {} }), }); redirect('/contact-success') } else if (valid && !validHostName) { redirect('/contact-success') } return (
Unable to send message. Please go back and reload the page and try again or try again later. Sorry!
Like the show? Want to hear us talk about something specific? Or just want to say hi? We’d love to hear from you!