How can PHP developers handle sending confirmation emails to users who fill out a form, while also sending a copy to a predefined email address, without compromising security or functionality?

Issue: PHP developers can handle sending confirmation emails to users who fill out a form, while also sending a copy to a predefined email address, by using the PHP `mail()` function to send the emails. To ensure security, developers should sanitize user input to prevent injection attacks and validate email addresses before sending. Additionally, using a separate email address for the predefined recipient can help maintain security and functionality.

<?php
// Sanitize user input
$user_email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);

// Validate email address
if (filter_var($user_email, FILTER_VALIDATE_EMAIL)) {
    // Send confirmation email to user
    $user_subject = "Confirmation Email";
    $user_message = "Thank you for filling out the form!";
    mail($user_email, $user_subject, $user_message);

    // Send copy to predefined email address
    $predefined_email = "predefined@example.com";
    $predefined_subject = "Copy of Confirmation Email";
    $predefined_message = "A copy of the confirmation email sent to the user.";
    mail($predefined_email, $predefined_subject, $predefined_message);
} else {
    echo "Invalid email address";
}
?>