Are there any best practices for handling multiple file uploads in PHPMail to ensure all attachments are sent successfully?

When handling multiple file uploads in PHPMail, it is important to loop through each file and add them as attachments to the PHPMailer object before sending the email. This ensures that all attachments are included in the email and sent successfully.

// Initialize PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

$mail = new PHPMailer(true);

// Loop through each uploaded file and add as attachment
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
    $file_name = $_FILES['files']['name'][$key];
    $file_type = $_FILES['files']['type'][$key];
    $file_size = $_FILES['files']['size'][$key];
    $file_tmp = $_FILES['files']['tmp_name'][$key];

    $mail->addAttachment($file_tmp, $file_name);
}

// Send the email
$mail->send();