false, 'message' => 'An unexpected error occurred.']; $userName = 'An anonymous user'; $userEmail = 'Not provided'; if (isset($_SESSION['user_id'])) { $userName = $_SESSION['user_name']; $userEmail = $_SESSION['user_email']; } $subject = 'SOS Alert Triggered by ' . $userName; $htmlBody = "
An SOS alert was triggered by:
" . "Please take appropriate action immediately.
"; $textBody = "SOS Alert from " . $userName . " (" . $userEmail . ") at " . date('Y-m-d H:i:s') . " UTC."; // Send the email. If no recipient is set in .env, it will use the default. $result = MailService::sendMail(null, $subject, $htmlBody, $textBody); if (!empty($result['success'])) { $response['success'] = true; $response['message'] = 'SOS alert sent successfully. Help is on the way.'; } else { // In a real app, you would log this error in more detail. $response['message'] = 'Failed to send SOS alert. Please try again or contact support.'; // For debugging, you might want to include the error, but not in production. // $response['error'] = $result['error']; } echo json_encode($response);