Are there specific encoding requirements for PDF attachments in PHP email headers?

When sending PDF attachments in PHP email headers, it is important to specify the correct encoding for the attachment to ensure it is properly handled by the recipient's email client. The encoding type should be set to "base64" for PDF attachments. This ensures that the attachment is encoded correctly and can be decoded by the recipient's email client.

$filename = 'example.pdf';
$file = file_get_contents($filename);
$encoded_file = chunk_split(base64_encode($file));

$boundary = md5(uniqid(time()));

$headers = "From: sender@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";

$message = "--$boundary\r\n";
$message .= "Content-Type: application/pdf; name=\"$filename\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition: attachment; filename=\"$filename\"\r\n\r\n";
$message .= $encoded_file."\r\n";
$message .= "--$boundary--";

mail('recipient@example.com', 'Subject', $message, $headers);