What are the common pitfalls when dealing with encoding of Mime-Mails in PHP?

Common pitfalls when dealing with encoding of Mime-Mails in PHP include not properly setting the content-type headers, not encoding special characters in the email body, and not handling attachments correctly. To solve these issues, make sure to set the content-type headers to specify the encoding type, use functions like `mb_encode_mimeheader()` to encode special characters, and properly handle attachments using libraries like PHPMailer.

// Set the content-type headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";

// Encode special characters in the email body
$subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";

// Handle attachments using PHPMailer library
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'your@example.com';
$mail->Password = 'yourpassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

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

$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;

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

$mail->send();