prepare(
'INSERT INTO applications (name, company, email, role) VALUES (?, ?, ?, ?)'
);
$stmt->execute([$name, $company, $email, $role]);
} catch (PDOException $e) {
// In a real app, log this error. For now, redirect with a generic error.
error_log('DB Error: ' . $e->getMessage());
header('Location: index.php?error=' . urlencode('A database error occurred.') . '#apply');
exit;
}
// 3. Email Notification
$to = getenv('MAIL_TO') ?: null; // Use admin email from .env
$subject = 'New FinMox Founding Access Application';
$htmlBody = "
New Application Received
A new application has been submitted for FinMox founding access:
- Name: " . htmlspecialchars($name) . "
- Company: " . htmlspecialchars($company) . "
- Email: " . htmlspecialchars($email) . "
- Role: " . htmlspecialchars($role) . "
";
$textBody = "New Application:\nName: $name\nCompany: $company\nEmail: $email\nRole: $role";
// Use MailService, but don't block the user if it fails
try {
MailService::sendMail($to, $subject, $htmlBody, $textBody);
} catch (Exception $e) {
// Log email error but don't prevent user from seeing success
error_log('MailService Error: ' . $e->getMessage());
}
// 4. Redirect to Success
header('Location: index.php?status=applied#apply');
exit;