In handling email attachments in PHP, what methods or libraries are recommended to avoid displaying attachments as a string of characters?

When handling email attachments in PHP, it is recommended to use the `PHPMailer` library as it provides a straightforward way to handle email attachments without displaying them as a string of characters. By using `PHPMailer`, you can easily attach files to your email and send them without worrying about the attachments being displayed as raw data.

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// Include PHPMailer autoload file
require 'vendor/autoload.php';

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

// Set up the SMTP settings
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'your@example.com';
$mail->Password = 'your_password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

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

// Set email details
$mail->setFrom('from@example.com', 'Your Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
$mail->Subject = 'Email with Attachments';
$mail->Body = 'Please find the attached files';

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