<?php
/**
* Email Functions for the Enrollment System
* Contains functions for sending various types of emails to users
*/
/**
* Send enrollment confirmation email to student
*
* @param string $email The recipient's email address
* @param string $name The recipient's name
* @param string $course_title The course title
* @param string $verification_token The verification token for the enrollment
* @return bool Whether the email was sent successfully
*/
function send_enrollment_confirmation_email($email, $name, $course_title, $verification_token) {
// Get school information from settings
global $conn;
$school_name = "Popular Computer Institute";
$school_email = "[email protected]";
// Try to fetch from settings if database connection exists
if (isset($conn) && $conn) {
$settings_query = "SELECT setting_value FROM settings WHERE setting_key = 'school_name' OR setting_key = 'school_email'";
$result = $conn->query($settings_query);
if ($result && $result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
if ($row['setting_key'] === 'school_name') {
$school_name = $row['setting_value'];
} elseif ($row['setting_key'] === 'school_email') {
$school_email = $row['setting_value'];
}
}
}
}
// Email headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "From: $school_name <$school_email>\r\n";
$headers .= "Reply-To: $school_email\r\n";
// Email subject
$subject = "Enrollment Confirmation: $course_title";
// Email body
$message = "
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
}
.header {
background-color: #4e73df;
color: white;
padding: 15px;
text-align: center;
border-radius: 5px 5px 0 0;
}
.content {
padding: 20px;
}
.footer {
text-align: center;
margin-top: 20px;
font-size: 0.8em;
color: #777;
}
.verification {
background-color: #f8f9fa;
padding: 15px;
border-radius: 5px;
text-align: center;
margin: 20px 0;
font-family: monospace;
font-size: 18px;
letter-spacing: 1px;
}
.button {
display: inline-block;
background-color: #4e73df;
color: white;
text-decoration: none;
padding: 10px 20px;
border-radius: 5px;
font-weight: bold;
}
</style>
</head>
<body>
<div class='container'>
<div class='header'>
<h2>Enrollment Confirmation</h2>
</div>
<div class='content'>
<p>Dear $name,</p>
<p>Congratulations! Your enrollment for <strong>$course_title</strong> has been successfully processed.</p>
<p>Please find your verification token below. You'll need to present this when you visit our institute to start your classes:</p>
<div class='verification'>
$verification_token
</div>
<p>Please keep this token safe and do not share it with anyone else.</p>
<p>If you have any questions or need further assistance, please don't hesitate to contact us.</p>
<p>We look forward to seeing you in class!</p>
<p>Best regards,<br>
The Team at $school_name</p>
</div>
<div class='footer'>
<p>This is an automated email. Please do not reply to this message.</p>
<p>© " . date('Y') . " $school_name. All rights reserved.</p>
</div>
</div>
</body>
</html>
";
// For now, just log that we would send the email
// In a production environment, you would use mail() or a library like PHPMailer
error_log("Would send enrollment confirmation email to $email for course $course_title");
// Simulating successful email sending
// In a real environment, you would return the result of mail() or your email library's send function
return true;
}
/**
* Send payment receipt email to student
*
* @param string $email The recipient's email address
* @param string $name The recipient's name
* @param string $course_title The course title
* @param string $transaction_id The payment transaction ID
* @param float $amount The payment amount
* @param string $payment_method The payment method used
* @param string $payment_plan The payment plan selected
* @return bool Whether the email was sent successfully
*/
function send_payment_receipt_email($email, $name, $course_title, $transaction_id, $amount, $payment_method, $payment_plan) {
// Implementation similar to send_enrollment_confirmation_email
// For now, just log that we would send the email
error_log("Would send payment receipt email to $email for transaction $transaction_id");
// Simulating successful email sending
return true;
}
/**
* Send enrollment notification to admin
*
* @param string $student_name The student's name
* @param string $student_email The student's email
* @param string $course_title The course title
* @param string $verification_token The verification token for the enrollment
* @return bool Whether the email was sent successfully
*/
function send_enrollment_notification_to_admin($student_name, $student_email, $course_title, $verification_token) {
// Implementation for admin notification
// For now, just log that we would send the email
error_log("Would send enrollment notification to admin about $student_name enrolling in $course_title");
// Simulating successful email sending
return true;
}