What are the best practices for handling multiple attachments in PHP when using phpMailer?

When handling multiple attachments in PHP with phpMailer, it is important to loop through each attachment and add them individually to the phpMailer instance. This ensures that each attachment is properly included in the email being sent.

// Instantiate phpMailer
$mail = new PHPMailer();

// Loop through each attachment and add them to the email
foreach ($attachments as $attachment) {
    $mail->addAttachment($attachment['path'], $attachment['name']);
}

// Send the email
if ($mail->send()) {
    echo 'Email sent successfully';
} else {
    echo 'Email could not be sent';
}