66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
require_once 'db/config.php';
|
|
require_once 'mail/MailService.php';
|
|
|
|
// 1. Validation
|
|
$name = trim($_POST['name'] ?? '');
|
|
$company = trim($_POST['company'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
$role = trim($_POST['role'] ?? '');
|
|
$error = '';
|
|
|
|
if (empty($name) || empty($company) || empty($email) || empty($role)) {
|
|
$error = 'All fields are required.';
|
|
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$error = 'Please enter a valid email address.';
|
|
}
|
|
|
|
if ($error) {
|
|
header('Location: index.php?error=' . urlencode($error) . '#apply');
|
|
exit;
|
|
}
|
|
|
|
// 2. Database Insert
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->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 = "
|
|
<h1>New Application Received</h1>
|
|
<p>A new application has been submitted for FinMox founding access:</p>
|
|
<ul>
|
|
<li><strong>Name:</strong> " . htmlspecialchars($name) . "</li>
|
|
<li><strong>Company:</strong> " . htmlspecialchars($company) . "</li>
|
|
<li><strong>Email:</strong> " . htmlspecialchars($email) . "</li>
|
|
<li><strong>Role:</strong> " . htmlspecialchars($role) . "</li>
|
|
</ul>
|
|
";
|
|
$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;
|
|
|