How can the selected email recipient from a drop-down menu be used to send the email in PHP?

To send an email to the selected recipient from a drop-down menu in PHP, you can use a form with a drop-down menu for selecting the recipient's email address. Once the form is submitted, you can retrieve the selected email address from the form data and use it as the recipient when sending the email using the PHP `mail()` function.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $recipient = $_POST['recipient'];
    $subject = "Your Subject Here";
    $message = "Your Message Here";
    $headers = "From: your_email@example.com";

    if (mail($recipient, $subject, $message, $headers)) {
        echo "Email sent successfully to $recipient";
    } else {
        echo "Email sending failed";
    }
}
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label for="recipient">Select recipient:</label>
    <select name="recipient" id="recipient">
        <option value="recipient1@example.com">Recipient 1</option>
        <option value="recipient2@example.com">Recipient 2</option>
        <option value="recipient3@example.com">Recipient 3</option>
    </select>
    <input type="submit" value="Send Email">
</form>