我想创建.eml
带有多个附件格式的电子邮件文件。附件已生成并且附件的内容是正确的。但附件始终采用.dat
格式,文件名为“ATT00001”、“ATT0002”..等
目前我正在关注this stackoverflow question中给出的解决方案,我的代码如下
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);
}
模板附件
--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
是上面链接中描述的主要电子邮件标题和正文。我的.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
上面的base64
内容给出了文件中正确的内容,PDF
当文件通过选择以打开时打开PDF Reader
。但是这些文件没有.pdf
格式。.xls
和.doc
所有其他文件类型也是如此。所有文件均.dat
采用标准命名格式而不是指定名称。
请帮我解决这个附件进来所需file type
的指定文件名。
注意:base64
示例.eml
文件中的内容被截断