$to = "example@example.com"; $subject = "Test email with attachment"; $message = "This is a test email with attachment."; $attachment = "/path/to/attachment/file.pdf"; // Headers for attaching the file $filename = basename($attachment); $content = chunk_split(base64_encode(file_get_contents($attachment))); $uid = md5(uniqid(time())); $from = "sender@example.com"; $headers = "From: ".$from."\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $headers .= "This is a multi-part message in MIME format.\r\n"; $headers .= "--".$uid."\r\n"; $headers .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $headers .= $message."\r\n\r\n"; $headers .= "--".$uid."\r\n"; $headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; $headers .= "Content-Transfer-Encoding: base64\r\n"; $headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $headers .= $content."\r\n\r\n"; // Send the email with attachment if (mail($to, $subject, "", $headers)) { // empty message body echo "Email with attachment sent successfully!"; } else { echo "Failed to send email with attachment"; }In this example, the addAttachment() function is used to attach a PDF file to the email. The package library used in this example is not clear, as the code uses the built-in PHP functions for file handling, encoding, and sending emails.