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 = '
Sai Baba Temple Donation Confirmation
Dear ' . htmlspecialchars($row['name']) . ',
Thank you for your generous donation. Here are the details:
| Name: | ' . $row['name'] . ' |
| Mobile: | ' . $row['mobile'] . ' |
| Email: | ' . $row['email'] . ' |
| Donation Date: | ' . $row['donation_date'] . ' |
| Amount: | ₹' . number_format($row['amount'], 2) . ' |
| PAN Number: | ' . $row['pan_number'] . ' |
| Address: | ' . $row['address'] . ', ' . $row['landmark'] . ', ' . $row['city'] . ', ' . $row['state'] . ', ' . $row['country'] . ' - ' . $row['zip_code'] . ' |
| Purpose: | ' . $row['purpose'] . ' |
';
// 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 "";
} catch (Exception $e) {
echo "Email could not be sent. Mailer Error: {$mail->ErrorInfo}";
unlink($pdfFile);
}
?>