[['to' => [['email' => $toEmail, 'name' => $toName]]]], 'from' => [ 'email' => defined('MAIL_FROM') ? MAIL_FROM : 'noreply@epictravelexpeditions.com', 'name' => defined('MAIL_FROM_NAME') ? MAIL_FROM_NAME : 'Epic Travel Expeditions', ], 'subject' => $subject, 'content' => array_values(array_filter([ $textBody ? ['type' => 'text/plain', 'value' => $textBody] : null, ['type' => 'text/html', 'value' => $htmlBody], ])), ]); $ch = curl_init('https://api.sendgrid.com/v3/mail/send'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $payload, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . $apiKey, 'Content-Type: application/json', ], CURLOPT_TIMEOUT => 20, CURLOPT_SSL_VERIFYPEER => false, ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 202) return true; error_log('[EpicTravel mailer] SendGrid HTTP ' . $httpCode . ' — ' . $response); return false; } function sendContactAlert(string $name, string $email, string $message): bool { $adminEmail = defined('ADMIN_EMAIL') ? ADMIN_EMAIL : 'admin@epictravelexpeditions.com'; $subject = "New Contact Form Submission from {$name}"; $html = '

Epic Travel Expeditions

New Contact Form Message

Name ' . htmlspecialchars($name) . '
Email ' . htmlspecialchars($email) . '

' . nl2br(htmlspecialchars($message)) . '

Submitted ' . date('F j, Y \a\t g:i A T') . '

© ' . date('Y') . ' Epic Travel Expeditions

'; return sendgridSend($adminEmail, 'Epic Travel Admin', $subject, $html, "New contact from {$name} ({$email}):\n\n{$message}"); } function sendContactConfirmation(string $toEmail, string $toName): bool { $subject = "We received your message — Epic Travel Expeditions"; $html = '

Epic Travel Expeditions

Thanks for reaching out, ' . htmlspecialchars($toName) . '!

We received your message and our team will get back to you within 1–2 business days.

In the meantime, feel free to browse our destinations and current travel specials:

Explore Destinations

Adventure awaits,
The Epic Travel Team

© ' . date('Y') . ' Epic Travel Expeditions

'; return sendgridSend($toEmail, $toName, $subject, $html, "Hi {$toName},\n\nThanks for contacting Epic Travel Expeditions! We'll get back to you within 1-2 business days.\n\nAdventure awaits,\nThe Epic Travel Team"); }