How can attachments be handled in the PHP script for sending emails?

To handle attachments in a PHP script for sending emails, you can use the PHPMailer library which provides an easy way to attach files to emails. You can use the `addAttachment()` method to add attachments to the email before sending it.

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

// Create a new PHPMailer instance
$mail = new PHPMailer();

// Set up the email parameters
$mail->setFrom('from@example.com', 'Your Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
$mail->Subject = 'Email with Attachment';
$mail->Body = 'This email contains an attachment.';

// Add attachment
$mail->addAttachment('/path/to/file.pdf');

// Send the email
if($mail->send()) {
    echo 'Email sent with attachment';
} else {
    echo 'Email could not be sent. Mailer Error: ' . $mail->ErrorInfo;
}
?>