How can PHP be used to redirect users to a PayPal page with specific donation options?

To redirect users to a PayPal page with specific donation options using PHP, you can create a form with hidden input fields containing the donation options and then submit the form programmatically using JavaScript.

<?php
// Define the donation options
$donationOptions = [
    'option1' => 10.00,
    'option2' => 20.00,
    'option3' => 30.00
];

// Generate the PayPal donation form
echo '<form id="paypalForm" action="https://www.paypal.com/cgi-bin/webscr" method="post">';
echo '<input type="hidden" name="cmd" value="_donations">';
echo '<input type="hidden" name="business" value="your_paypal_email@example.com">';
echo '<input type="hidden" name="currency_code" value="USD">';
echo '<input type="hidden" name="item_name" value="Donation">';
echo '<select name="amount">';
foreach ($donationOptions as $option => $amount) {
    echo '<option value="' . $amount . '">' . $option . ' - $' . $amount . '</option>';
}
echo '</select>';
echo '<input type="hidden" name="no_note" value="1">';
echo '<input type="hidden" name="no_shipping" value="1">';
echo '<input type="hidden" name="rm" value="2">';
echo '<input type="hidden" name="return" value="https://yourwebsite.com/thankyou.php">';
echo '</form>';

// Submit the form using JavaScript
echo '<script>document.getElementById("paypalForm").submit();</script>';
?>