File Manager Script
X

Create New Item

File Folder

X

Search Results

File "deposit_process.php"

Full path: /home/quiczmwg/lightspringdigitals.com/../../quiczmwg/solixproperties.org/deposit_process.php
File size: 5.26 KiB (5386 bytes)
MIME-type: text/x-php; charset=us-ascii
Charset: utf-8

Download   Open   Edit   Advanced Edit   Back

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

session_start();

// Include your database connection file
include_once('_db.php');

// Include PHPMailer for email functionality
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php'; // Ensure PHPMailer is installed via Composer

// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    try {
        // Retrieve form data including the user ID
        if (!isset($_POST['userid'])) {
            throw new Exception("User ID not found in form data.");
        }
        
        // Fetch the username and email from the database based on the userid
        $userid = $_POST['userid'];
        $stmt_user = $conn->prepare("SELECT username, email FROM user_login WHERE userid = ?");
        $stmt_user->bind_param("s", $userid);
        $stmt_user->execute();
        $result = $stmt_user->get_result();
        $row = $result->fetch_assoc();
        if (!$row) {
            throw new Exception("User not found in the database.");
        }
        $username = $row['username'];
        $email = $row['email'];

        $amount = $_POST['amount'];
        $walletType = $_POST['wallet_type'];
        // Retrieve file data for proof of payment
        $proofOfPayment = $_FILES['proof_of_payment'];

        // Validate and sanitize the input data
        $amount = filter_var($amount, FILTER_VALIDATE_FLOAT);
        $walletType = filter_var($walletType, FILTER_SANITIZE_FULL_SPECIAL_CHARS);

        // Move uploaded file (proof of payment) to a specified directory
        $targetDir = "uploads/"; // Specify the directory where you want to store uploaded files
        $targetFile = $targetDir . basename($proofOfPayment["name"]);
        move_uploaded_file($proofOfPayment["tmp_name"], $targetFile);

        // Insert the deposit details into the database
        $deposit_id = md5(uniqid());
        $stmt = $conn->prepare("INSERT INTO deposit (userid, username, deposit_id, amount, wallet_type, proof_of_payment, wallet_address) VALUES (?, ?, ?, ?, ?, ?, ?)");
        $stmt->bind_param("sssssss", $userid, $username, $deposit_id, $amount, $walletType, $targetFile, $_POST['wallet_address_input']); // Assuming wallet_address_input is a string
        $stmt->execute();

        // Check if the insertion was successful
        if ($stmt->affected_rows > 0) {
            // Send an email to the user using PHPMailer
            $mail = new PHPMailer(true);

            try {
                // Server settings
                $mail->isSMTP();
                $mail->Host = 'solixproperties.org'; // SMTP server for your domain
                $mail->SMTPAuth = true;
                $mail->Username = 'support@solixproperties.org'; // SMTP username (your email address)
                $mail->Password = '@solixproperties.org!'; // SMTP password
                $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable SMTPS (SSL)
                $mail->Port = 465; // SMTP port for SSL

                // Recipients
                $mail->setFrom('support@solixproperties.org', 'Solix Properties');
                $mail->addAddress($email, $username); // Add recipient

                // Attach the logo
                $logoPath = 'img/logo.jpeg'; // Replace with the actual path to your logo file
                $mail->addEmbeddedImage($logoPath, 'logo_cid');

                // Content
                $mail->isHTML(true);
                $mail->Subject = "Deposit Received - Your Wallet Deposit Request";
                $mail->Body = "<div style='text-align: center;'>
                        <img src='cid:logo_cid' alt='Solix Properties Logo' style='width: 150px; margin-bottom: 20px;'>
                    </div>
                    <p>Hello $username,</p>
                    <p>We have received your deposit request of <strong>$" . number_format($amount, 2) . "</strong>. Your wallet will be credited once the admin confirms your payment.</p>
                    <p><strong>Deposit Details:</strong></p>
                    <ul>
                        <li>Wallet Type: $walletType</li>
                        <li>Amount: $" . number_format($amount, 2) . "</li>
                    </ul>
                    <p>Thank you for using our service.</p>
                    <p>Best regards,<br>Solix Properties</p>";
                $mail->AltBody = "Hello $username,\n\nWe have received your deposit request of $" . number_format($amount, 2) . ". Your wallet will be credited once the admin confirms your payment.\n\nDeposit Details:\n- Wallet Type: $walletType\n- Amount: $" . number_format($amount, 2) . "\n\nThank you for using our service.\n\nBest regards,\nSolix Properties";

                $mail->send();
            } catch (Exception $e) {
                throw new Exception("Email could not be sent. Mailer Error: {$mail->ErrorInfo}");
            }

            // Redirect to the deposit page with success status
            header("Location: deposit.php?status=success");
            exit();
        } else {
            // Redirect to the deposit page with error status
            header("Location: deposit.php?status=error");
            exit();
        }
    } catch (Exception $e) {
        // Handle exceptions
        echo "Exception: " . $e->getMessage();
    }
}
?>