What are the limitations of sending multipart messages in PHP emails with attachments?

When sending multipart messages in PHP emails with attachments, one limitation is that some email clients may not display the attachments correctly or at all. To ensure that attachments are properly displayed, it is important to set the appropriate headers and encode the attachments properly.

// Set the appropriate headers for sending multipart messages with attachments
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"boundary\"\r\n";

// Encode the attachment file
$attachment = chunk_split(base64_encode(file_get_contents('attachment.pdf')));

// Construct the message body
$message = "--boundary\r\n";
$message .= "Content-Type: text/plain; charset=\"utf-8\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "\r\n";
$message .= "This is a multipart message with attachments.\r\n";
$message .= "\r\n";
$message .= "--boundary\r\n";
$message .= "Content-Type: application/pdf; name=\"attachment.pdf\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition: attachment; filename=\"attachment.pdf\"\r\n";
$message .= "\r\n";
$message .= $attachment . "\r\n";
$message .= "--boundary--";

// Send the email with attachments
mail('recipient@example.com', 'Subject', $message, $headers);