附件名称和文件扩展名不适用于电子邮件*.eml

mit*_*atw 6 php email zend-framework eml email-attachments

我想创建.eml具有多个附件的格式的电子邮件文件.生成附件并且附件的内容是正确的.但附件总是以.dat格式出现,文件名称为"ATT00001","ATT0002"等

目前我正在遵循此stackoverflow问题中给出的解决方案,我的代码如下

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);
    }
Run Code Online (Sandbox Code Playgroud)

模板附件

--080107000800000609090108
Content-Type: "TEMPLATE_MIME_TYPE"
name="TEMPLATE_FILE_NAME"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="TEMPLATE_FILE_NAME"

TEMPLATE_ATTACHMENT_CONTENT
Run Code Online (Sandbox Code Playgroud)

$content是上面链接中描述的主要电子邮件标题和正文.我的.eml档案看起来像;

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
Run Code Online (Sandbox Code Playgroud)

通过选择打开文件打开文件时,上面base64的内容在PDF文件中给出了正确的内容PDF Reader.但文件不是.pdf格式化的.同样的情况发生了.xls,.doc和所有其他类型的文件.所有文件都.dat采用标准命名格式,而不是指定的名称.

请帮我解决这个file type带有指定文件名所需的附件.

注意:base64示例.eml文件中的内容被截断

mit*_*atw 4

我找到了自己的答案.. !! 标题Template_Attachment应如下

--080107000800000609090108
Content-Type: TEMPLATE_MIME_TYPE;name="TEMPLATE_FILE_NAME"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;filename="TEMPLATE_FILE_NAME"

TEMPLATE_ATTACHMENT_CONTENT
Run Code Online (Sandbox Code Playgroud)

哪里080107000800000609090108是界限在这种情况下,在所有附件的结束,应该有另一个080107000800000609090108结束电子邮件.

希望有一天这会对某人有所帮助:-)

PS:所以实际.eml文件看起来如下所示,它应该做得很好

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"

JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovQ29udGVasdsDFDffjMBakdjKJHBzdHlsZT0iY29=

--080107000800000609090108
Content-Type: application/excel;name="AM22831 Manufacturing Status.xls"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;filename="AM22831 Manufacturing Status.xls"

DQoNCjx0YWJsZSBib3JkZXI9IjAiPg0KPHRyPg0KPHRkIGNvbHNwYW49IjMiIHJvd3NwYW49IjIiIGFsaWduPSJjZW50ZXIiPg0KICAgIDxoMSBzdHlsZT0iY29=
Run Code Online (Sandbox Code Playgroud)