Are there any specific best practices for sending files via email using PHP?

When sending files via email using PHP, it's important to properly encode the file content and set the appropriate headers to ensure the file is correctly attached and sent. One common best practice is to use the `multipart/mixed` MIME type to include both the email message and the file attachment.

<?php
$to = 'recipient@example.com';
$subject = 'File Attachment';
$message = 'Please see the attached file.';
$file_path = '/path/to/file.pdf';

$filename = basename($file_path);
$file_content = file_get_contents($file_path);
$attachment = chunk_split(base64_encode($file_content));

$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";

$body = "--{$boundary}\r\n";
$body .= "Content-Type: text/plain; charset=\"UTF-8\"\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= "{$message}\r\n";

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

$body .= "--{$boundary}--";

mail($to, $subject, $body, $headers);
?>