In the context of the provided PHP code, what are the potential issues with constructing the mail body for sending attachments via email?

The potential issue with constructing the mail body for sending attachments via email is that the attachments may not be properly encoded or formatted, leading to errors or the attachments not being sent correctly. To solve this, we can use the PHP `mail()` function along with the `mail->AddAttachment()` method from the PHPMailer library to ensure that the attachments are properly handled and sent in the email.

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

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->isSMTP();
    $mail->Host = 'smtp.example.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'your@example.com';
    $mail->Password = 'yourpassword';
    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;

    //Recipients
    $mail->setFrom('from@example.com', 'Your Name');
    $mail->addAddress('recipient@example.com', 'Recipient Name');

    // Attachments
    $mail->addAttachment('/path/to/file1.pdf', 'File1.pdf');
    $mail->addAttachment('/path/to/file2.jpg', 'File2.jpg');

    // Content
    $mail->isHTML(true);
    $mail->Subject = 'Subject here';
    $mail->Body = 'Email body here';

    $mail->send();
    echo 'Email has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}