How can PHP be used to send emails with dynamic recipient addresses based on form input?

To send emails with dynamic recipient addresses based on form input in PHP, you can use the `mail()` function along with the `$_POST` superglobal to retrieve the form input data. You can then use this data to dynamically set the recipient address in the `mail()` function.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $recipient = $_POST['recipient_email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    
    if (mail($recipient, $subject, $message)) {
        echo "Email sent successfully to $recipient";
    } else {
        echo "Email sending failed";
    }
}
?>