电子邮件中的附件名称和文件扩展名* .eml [英] Attachment name and file extension not working in email *.eml
问题描述
我想在 .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);
}
模板附件
- 080107000800000609090108
内容类型:TEMPLATE_MIME_TYPE
name =TEMPLATE_FILE_NAME
Content-Transfer-Encoding: base64
Content-Disposition:attachment;
filename =TEMPLATE_FILE_NAME
TEMPLATE_ATTACHMENT_CONTENT
$ content
是上述链接中描述的主要电子邮件标题和正文。我的 .eml
文件看起来像;
MIME版本:1.0
pre>
日期:星期二,2013年4月16日09:03:37 +0100
发件人:sender@emailhost.com
收件人:recipient@emailhost.com
主题:电子邮件主题
内容类型:multipart / mixed boundary =080107000800000609090108
这是一个包含MIME格式多个部分的消息。
--080107000800000609090108
内容类型:text / html
< p>< strong>项目名称:一些项目和身体继续... < / p为H.
--080107000800000609090108
内容类型:application / pdf
name =AM22831 - - Cover Sheet.pdf
Content-Transfer-Encoding:base64
Content-Disposition:attachment;
=文件名 AM22831 - - 封面Sheet.pdf
JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovQ29udGVudHMgNCAwICiUlRU9GCg ==
--080107000800000609090108
的含量-Type:application / pdf
name =AM22831 - - Manufacturing Status.pdf
Content-Transfer-Encoding:base64
Content-Disposition:attachment;
filename =AM22831 - - 制造状态.pdf
cSAxMTMuMzkgMCAwIDMwLjUzIDE0LjE3IDU1MC41OCBjbSAvSTEgRG8gUQpxIDAuMDAwIDAuMDAwIDEuMDAwIHJnIEJUIDEzMC4zOSRU9GCg ==
--080107000800000609090108
上述
base64
内容在PDF中提供正确的内容
文件通过选择使用PDF阅读器
打开时打开。但文件不在.xls
,.doc
和所有其他文件类型也是一样。所有的文件都以.dat
格式与标准命名而不是指定的名称。
请帮我解决此附件进入所需的
文件类型
与指定的文件名。
注意:
$ 64
解决方案 div>我找到答案我的自我..
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
其中
080107000800000609090108
是这种情况下的边界,所有附件的结尾,应该有另一个080107000800000609090108
结束电子邮件。
希望这将有所帮助有人有一天: - )
PS:所以实际的
.eml
文件看起来像下面这样完美的它应该做MIME版本:1.0
日期:星期二,2013年4月16日09:03:37 +0100
From:sender@emailhost.com
至:recipient@emailhost.com
主题:电子邮件主题
内容类型:multipart / mixed; boundary =080107000800000609090108
这是一个包含MIME格式多个部分的消息。
--080107000800000609090108
内容类型:text / html
< p>< strong>项目名称:一些项目和身体继续... < / p为H.
--080107000800000609090108
内容类型:application / pdf; name =AM22831 Cover Sheet.pdf
内容转移编码:base64
内容处理:附件;文件名= AM22831封面Sheet.pdf
JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovQ29udGVasdsDFDffjMBakdjKJHBzdHlsZT0iY29 =
--080107000800000609090108
内容类型:应用/ EXCEL;名称=AM22831制造Status.xls
含量传输编码:BASE64
内容处置:附件;文件名= AM22831制造Status.xls
DQoNCjx0YWJsZSBib3JkZXI9IjAiPg0KPHRyPg0KPHRkIGNvbHNwYW49IjMiIHJvd3NwYW49IjIiIGFsaWduPSJjZW50ZXIiPg0KICAgIDxoMSBzdHlsZT0iY29 =
I want to create email files in
.eml
format with multiple attachments in. The attachments are generated and the content of the attachments are correct. But the attachments always come in.dat
format and the file names go as "ATT00001", "ATT0002".. etcCurrently I am following the solution given in this stackoverflow 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); }
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
$content
is the main email header and body as described in the above link. My.eml
file looks like;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 right content in thePDF Reader
. But the files do not come in.xls
,.doc
and all other file types. All the files come in.dat
format with standard naming rather than the specified names.Please help me to solve this attachments come in the required
file type
with specified file name.NB: The
base64
content in the sample.eml
file is truncated解决方案I found the answer my self..!! The header of
Template_Attachment
should be as follows--080107000800000609090108 Content-Type: TEMPLATE_MIME_TYPE;name="TEMPLATE_FILE_NAME" Content-Transfer-Encoding: base64 Content-Disposition: attachment;filename="TEMPLATE_FILE_NAME" TEMPLATE_ATTACHMENT_CONTENT
Where
080107000800000609090108
is the boundary in this case and at the end of all attachments, there should be another080107000800000609090108
to end the email.Hope this would be helpful to somebody someday :-)
PS: so the actual
.eml
file would look like as follows which works perfect as it should doMIME-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=
这篇关于电子邮件中的附件名称和文件扩展名* .eml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文