Path : /home/vishqocm/pcib.in/includes/
File Upload :
Current File : /home/vishqocm/pcib.in/includes/email_functions.php

<?php
/**
 * Email Functions
 * 
 * This file contains functions for sending emails related to enrollment
 */

/**
 * Send an enrollment confirmation email
 * 
 * @param string $to Email address to send to
 * @param string $name Recipient's name
 * @param string $course_title Course title
 * @param string $verification_token Verification token for the enrollment
 * @return bool True if email was sent, false otherwise
 */
function send_enrollment_confirmation_email($to, $name, $course_title, $verification_token) {
    // Email headers
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= "From: Popular Computer Institute <[email protected]>" . "\r\n";
    
    // Email subject
    $subject = "Enrollment Confirmation - $course_title";
    
    // Email body
    $body = '
    <!DOCTYPE html>
    <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: 10px 20px;
                text-align: center;
                border-radius: 5px 5px 0 0;
            }
            .content {
                padding: 20px;
            }
            .footer {
                text-align: center;
                padding: 10px;
                font-size: 12px;
                color: #777;
                border-top: 1px solid #ddd;
            }
            .verification-token {
                background-color: #f8f9fc;
                border: 1px solid #ddd;
                padding: 15px;
                margin: 20px 0;
                text-align: center;
                font-size: 18px;
                letter-spacing: 2px;
                font-weight: bold;
            }
            .button {
                display: inline-block;
                padding: 10px 20px;
                background-color: #4e73df;
                color: white;
                text-decoration: none;
                border-radius: 5px;
                margin-top: 15px;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="header">
                <h2>Enrollment Confirmation</h2>
            </div>
            <div class="content">
                <p>Dear ' . htmlspecialchars($name) . ',</p>
                
                <p>Thank you for enrolling in <strong>' . htmlspecialchars($course_title) . '</strong> at Popular Computer Institute.</p>
                
                <p>Your enrollment has been confirmed and is now complete. Please save the verification token below to access your classes:</p>
                
                <div class="verification-token">' . $verification_token . '</div>
                
                <p><strong>Important:</strong> You must present this verification token when you visit our institute to start your classes.</p>
                
                <p>You can also access your course details and verification token from your student dashboard.</p>
                
                <p>If you have any questions or need assistance, please contact our support team.</p>
                
                <p>Best regards,<br>
                Popular Computer Institute</p>
            </div>
            <div class="footer">
                <p>&copy; ' . date('Y') . ' Popular Computer Institute. All rights reserved.</p>
                <p>This is an automated email, please do not reply.</p>
            </div>
        </div>
    </body>
    </html>
    ';
    
    // Send email
    $mail_sent = mail($to, $subject, $body, $headers);
    
    // Log email sending result
    if (!$mail_sent) {
        error_log("Failed to send enrollment confirmation email to $to for course $course_title");
    }
    
    return $mail_sent;
}

/**
 * Send a document verification email
 * 
 * @param string $to Email address to send to
 * @param string $name Recipient's name
 * @param string $course_title Course title
 * @param string $status Verification status
 * @param string $message Additional message
 * @return bool True if email was sent, false otherwise
 */
function send_document_verification_email($to, $name, $course_title, $status, $message = '') {
    // Email headers
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= "From: Popular Computer Institute <[email protected]>" . "\r\n";
    
    // Email subject
    $subject = "Document Verification - $course_title";
    
    // Status color
    $status_color = ($status == 'verified') ? '#28a745' : (($status == 'rejected') ? '#dc3545' : '#ffc107');
    
    // Email body
    $body = '
    <!DOCTYPE html>
    <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: 10px 20px;
                text-align: center;
                border-radius: 5px 5px 0 0;
            }
            .content {
                padding: 20px;
            }
            .footer {
                text-align: center;
                padding: 10px;
                font-size: 12px;
                color: #777;
                border-top: 1px solid #ddd;
            }
            .status {
                background-color: ' . $status_color . ';
                color: white;
                padding: 5px 10px;
                border-radius: 3px;
                font-weight: bold;
                display: inline-block;
                text-transform: uppercase;
            }
            .message {
                background-color: #f8f9fc;
                border: 1px solid #ddd;
                padding: 15px;
                margin: 20px 0;
            }
            .button {
                display: inline-block;
                padding: 10px 20px;
                background-color: #4e73df;
                color: white;
                text-decoration: none;
                border-radius: 5px;
                margin-top: 15px;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="header">
                <h2>Document Verification Update</h2>
            </div>
            <div class="content">
                <p>Dear ' . htmlspecialchars($name) . ',</p>
                
                <p>Your document verification for <strong>' . htmlspecialchars($course_title) . '</strong> enrollment has been updated.</p>
                
                <p>Verification Status: <span class="status">' . ucfirst($status) . '</span></p>';
    
    if (!empty($message)) {
        $body .= '<div class="message">' . htmlspecialchars($message) . '</div>';
    }
    
    if ($status == 'verified') {
        $body .= '<p>Your documents have been verified successfully. Please proceed with the payment to complete your enrollment.</p>';
    } elseif ($status == 'rejected') {
        $body .= '<p>Please upload new documents with the required corrections and specifications.</p>';
    }
    
    $body .= '
                <p>You can log in to your student account to check the status of your enrollment and take necessary actions.</p>
                
                <p>If you have any questions or need assistance, please contact our support team.</p>
                
                <p>Best regards,<br>
                Popular Computer Institute</p>
            </div>
            <div class="footer">
                <p>&copy; ' . date('Y') . ' Popular Computer Institute. All rights reserved.</p>
                <p>This is an automated email, please do not reply.</p>
            </div>
        </div>
    </body>
    </html>
    ';
    
    // Send email
    $mail_sent = mail($to, $subject, $body, $headers);
    
    // Log email sending result
    if (!$mail_sent) {
        error_log("Failed to send document verification email to $to for course $course_title");
    }
    
    return $mail_sent;
}

/**
 * Send a payment confirmation email
 * 
 * @param string $to Email address to send to
 * @param string $name Recipient's name
 * @param string $course_title Course title
 * @param float $amount Payment amount
 * @param string $transaction_id Transaction ID
 * @param string $payment_method Payment method
 * @return bool True if email was sent, false otherwise
 */
function send_payment_confirmation_email($to, $name, $course_title, $amount, $transaction_id, $payment_method) {
    // Email headers
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= "From: Popular Computer Institute <[email protected]>" . "\r\n";
    
    // Email subject
    $subject = "Payment Confirmation - $course_title";
    
    // Email body
    $body = '
    <!DOCTYPE html>
    <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: 10px 20px;
                text-align: center;
                border-radius: 5px 5px 0 0;
            }
            .content {
                padding: 20px;
            }
            .footer {
                text-align: center;
                padding: 10px;
                font-size: 12px;
                color: #777;
                border-top: 1px solid #ddd;
            }
            .payment-details {
                background-color: #f8f9fc;
                border: 1px solid #ddd;
                padding: 15px;
                margin: 20px 0;
            }
            .payment-details table {
                width: 100%;
                border-collapse: collapse;
            }
            .payment-details th, .payment-details td {
                padding: 8px;
                text-align: left;
                border-bottom: 1px solid #ddd;
            }
            .payment-details th {
                width: 40%;
            }
            .button {
                display: inline-block;
                padding: 10px 20px;
                background-color: #4e73df;
                color: white;
                text-decoration: none;
                border-radius: 5px;
                margin-top: 15px;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="header">
                <h2>Payment Confirmation</h2>
            </div>
            <div class="content">
                <p>Dear ' . htmlspecialchars($name) . ',</p>
                
                <p>Thank you for your payment for the course <strong>' . htmlspecialchars($course_title) . '</strong>.</p>
                
                <div class="payment-details">
                    <h3>Payment Details</h3>
                    <table>
                        <tr>
                            <th>Course</th>
                            <td>' . htmlspecialchars($course_title) . '</td>
                        </tr>
                        <tr>
                            <th>Amount Paid</th>
                            <td>₹' . number_format($amount, 2) . '</td>
                        </tr>
                        <tr>
                            <th>Transaction ID</th>
                            <td>' . $transaction_id . '</td>
                        </tr>
                        <tr>
                            <th>Payment Method</th>
                            <td>' . ucwords(str_replace('_', ' ', $payment_method)) . '</td>
                        </tr>
                        <tr>
                            <th>Date</th>
                            <td>' . date('d M Y h:i A') . '</td>
                        </tr>
                    </table>
                </div>
                
                <p>Your enrollment is now complete. You can access your course from your student dashboard.</p>
                
                <p>If you have any questions or need assistance, please contact our support team.</p>
                
                <p>Best regards,<br>
                Popular Computer Institute</p>
            </div>
            <div class="footer">
                <p>&copy; ' . date('Y') . ' Popular Computer Institute. All rights reserved.</p>
                <p>This is an automated email, please do not reply.</p>
            </div>
        </div>
    </body>
    </html>
    ';
    
    // Send email
    $mail_sent = mail($to, $subject, $body, $headers);
    
    // Log email sending result
    if (!$mail_sent) {
        error_log("Failed to send payment confirmation email to $to for course $course_title");
    }
    
    return $mail_sent;
}
?>