I want to create email files in .eml format with several attachments. Attachments are created and the contents of the attachments are correct. But attachments always come in .dat format, and file names go like "ATT00001", "ATT0002", etc.
I am currently following the solution mentioned in this thread_stack question and my code is as follows
Php
foreach($reports as $pdf){ $attachment = file_get_contents("auto_report_attachments\\Template_Attachment.eml"); $attachment = str_replace("TEMPLATE_MIME_TYPE", $pdf['type'], $attachment); $attachment = str_replace("TEMPLATE_FILE_NAME", $pdf['filename'], $attachment); $attachment = str_replace("TEMPLATE_ATTACHMENT_CONTENT", base64_encode($pdf['file']), $attachment); $content .= $attachment; unset($attachment); }
Nesting Templates
--080107000800000609090108 Content-Type: "TEMPLATE_MIME_TYPE" name="TEMPLATE_FILE_NAME" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="TEMPLATE_FILE_NAME" TEMPLATE_ATTACHMENT_CONTENT
$content is the main email header and body, as described in the link above. My .eml looks like this:
MIME-Version: 1.0 Date: Tue, 16 Apr 2013 09:03:37 +0100 From: sender@emailhost.com To: recipient@emailhost.com Subject: Email subject Content-Type: multipart/mixed; boundary="080107000800000609090108" This is a message with multiple parts in MIME format. --080107000800000609090108 Content-Type: text/html <p><strong>Project Name: Some Project and the body continues...</p> --080107000800000609090108 Content-Type: "application/pdf" name="AM22831 - - Cover Sheet.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="AM22831 - - Cover Sheet.pdf" JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovQ29udGVudHMgNCAwICiUlRU9GCg== --080107000800000609090108 Content-Type: "application/pdf" name="AM22831 - - Manufacturing Status.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="AM22831 - - Manufacturing Status.pdf" cSAxMTMuMzkgMCAwIDMwLjUzIDE0LjE3IDU1MC41OCBjbSAvSTEgRG8gUQpxIDAuMDAwIDAuMDAwIDEuMDAwIHJnIEJUIDEzMC4zOSRU9GCg== --080107000800000609090108
The above base64 content gives the correct content in the PDF file when the file is opened by choosing to open with PDF Reader . But the files are not included in the .pdf format. The same thing happens for .xls , .doc and all other file types. All files are in .dat format with a standard name, not with the specified names.
Please help me in solving these attachments to enter the required file type with the specified file name.
Note. base64 content in .eml sample truncated
mithilatw
source share