我想创建.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 …Run Code Online (Sandbox Code Playgroud)