What are the security considerations when designing an internal mail system in PHP that allows sending emails to multiple recipients?

When designing an internal mail system in PHP that allows sending emails to multiple recipients, it is important to sanitize and validate the input data to prevent email injection attacks. Additionally, ensure that only authorized users have permission to send emails to multiple recipients to prevent misuse of the system. Implementing proper validation and authorization checks can help maintain the security of the internal mail system.

// Example of sanitizing and validating input data for sending emails to multiple recipients

// Validate and sanitize the input data
$recipients = filter_var_array($_POST['recipients'], FILTER_VALIDATE_EMAIL);

// Check if the user is authorized to send emails to multiple recipients
if (userHasPermission($_SESSION['user_id'])) {
    // Send the email to multiple recipients
    foreach ($recipients as $recipient) {
        mail($recipient, 'Subject', 'Message');
    }
} else {
    echo 'You are not authorized to send emails to multiple recipients.';
}

// Function to check if the user has permission to send emails to multiple recipients
function userHasPermission($userId) {
    // Implement your authorization logic here
    return true; // For demonstration purposes
}