feat: add user confirmation email and admin BCC for contact form submissions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
da0e2367c0
commit
683ff54cdb
@@ -194,9 +194,11 @@ async function sendContactEmail(data: ContactFormData): Promise<void> {
|
|||||||
|
|
||||||
const fromAddress = smtpFrom || smtpUser;
|
const fromAddress = smtpFrom || smtpUser;
|
||||||
|
|
||||||
const info = await smtpTransporter.sendMail({
|
// 1) Admin notification email with BCC to SMTP_USER for delivery confirmation
|
||||||
|
const adminInfo = await smtpTransporter.sendMail({
|
||||||
from: `"CompanySite Contact Form" <${fromAddress}>`,
|
from: `"CompanySite Contact Form" <${fromAddress}>`,
|
||||||
to: recipientEmail,
|
to: recipientEmail,
|
||||||
|
bcc: process.env.SMTP_USER, // BCC to admin inbox as delivery confirmation
|
||||||
replyTo: data.email,
|
replyTo: data.email,
|
||||||
subject: `[Contact Form] ${subjectLabels[data.subject] ?? data.subject} - ${data.name}`,
|
subject: `[Contact Form] ${subjectLabels[data.subject] ?? data.subject} - ${data.name}`,
|
||||||
text: [
|
text: [
|
||||||
@@ -226,7 +228,46 @@ async function sendContactEmail(data: ContactFormData): Promise<void> {
|
|||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return info;
|
// 2) User confirmation email — proves delivery works AND provides good UX
|
||||||
|
const userConfirmInfo = await smtpTransporter.sendMail({
|
||||||
|
from: `"CompanySite" <${fromAddress}>`,
|
||||||
|
to: data.email,
|
||||||
|
subject: 'We received your message - CompanySite',
|
||||||
|
text: [
|
||||||
|
`Hi ${data.name},`,
|
||||||
|
``,
|
||||||
|
`Thank you for reaching out to us! We have received your message regarding "${subjectLabels[data.subject] ?? data.subject}".`,
|
||||||
|
``,
|
||||||
|
`Our team will review your inquiry and get back to you as soon as possible, typically within 1-2 business days.`,
|
||||||
|
``,
|
||||||
|
`For your reference, here is a summary of your submission:`,
|
||||||
|
` Subject: ${subjectLabels[data.subject] ?? data.subject}`,
|
||||||
|
` Date: ${new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })}`,
|
||||||
|
``,
|
||||||
|
`If you have any urgent questions, feel free to reply to this email.`,
|
||||||
|
``,
|
||||||
|
`Best regards,`,
|
||||||
|
`The CompanySite Team`,
|
||||||
|
].join('\n'),
|
||||||
|
html: `
|
||||||
|
<div style="font-family:Arial,sans-serif;max-width:600px;margin:0 auto;padding:20px">
|
||||||
|
<h2 style="color:#333">Thank you for contacting us!</h2>
|
||||||
|
<p>Hi ${escapeHtml(data.name)},</p>
|
||||||
|
<p>We have received your message regarding <strong>"${escapeHtml(subjectLabels[data.subject] ?? data.subject)}"</strong>.</p>
|
||||||
|
<p>Our team will review your inquiry and get back to you as soon as possible, typically within <strong>1-2 business days</strong>.</p>
|
||||||
|
<div style="background:#f9f9f9;border-left:4px solid #007bff;padding:12px 16px;margin:20px 0">
|
||||||
|
<p style="margin:4px 0"><strong>Subject:</strong> ${escapeHtml(subjectLabels[data.subject] ?? data.subject)}</p>
|
||||||
|
<p style="margin:4px 0"><strong>Date:</strong> ${new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })}</p>
|
||||||
|
</div>
|
||||||
|
<p>If you have any urgent questions, feel free to reply to this email.</p>
|
||||||
|
<p style="margin-top:24px">Best regards,<br><strong>The CompanySite Team</strong></p>
|
||||||
|
<hr style="border:none;border-top:1px solid #eee;margin-top:24px">
|
||||||
|
<p style="color:#888;font-size:12px">This is an automated confirmation. Please do not reply unless you need further assistance.</p>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
|
||||||
|
return { adminInfo, userConfirmInfo };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// If nodemailer isn't installed, treat as graceful degradation (log only)
|
// If nodemailer isn't installed, treat as graceful degradation (log only)
|
||||||
if (err instanceof Error && err.message.includes('Cannot find module')) {
|
if (err instanceof Error && err.message.includes('Cannot find module')) {
|
||||||
@@ -374,14 +415,18 @@ export const POST: APIRoute = async ({ request, clientAddress }) => {
|
|||||||
console.log('Sending contact email to: ' + recipientEmail);
|
console.log('Sending contact email to: ' + recipientEmail);
|
||||||
|
|
||||||
sendContactEmail(formData)
|
sendContactEmail(formData)
|
||||||
.then((info) => {
|
.then((result) => {
|
||||||
console.log('Contact email delivered successfully to:', recipientEmail, {
|
console.log('Contact emails delivered successfully:', {
|
||||||
messageId: info?.messageId,
|
adminRecipient: recipientEmail,
|
||||||
|
adminMessageId: result?.adminInfo?.messageId,
|
||||||
|
userRecipient: formData.email,
|
||||||
|
userMessageId: result?.userConfirmInfo?.messageId,
|
||||||
});
|
});
|
||||||
logger.info('api.contact', 'Contact email delivered successfully', {
|
logger.info('api.contact', 'Contact emails delivered successfully', {
|
||||||
recipient: recipientEmail,
|
adminRecipient: recipientEmail,
|
||||||
messageId: info?.messageId,
|
adminMessageId: result?.adminInfo?.messageId,
|
||||||
from: formData.email,
|
userRecipient: formData.email,
|
||||||
|
userMessageId: result?.userConfirmInfo?.messageId,
|
||||||
subject: formData.subject,
|
subject: formData.subject,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user