我使用下面的代码使用IMAP_APPEND将多个附件添加到已发送文件夹中的邮件中。在发送文件夹中,我只获得一个附件而不是其他附件..任何人都可以建议这个问题是什么?
if ($mbox=imap_open( $authhost, $user, $pass))
{
$dmy=date("d-M-Y H:i:s");
$boundary = "------=" . md5(uniqid(rand()));
$msg .= "From: ".$from[0]."\r\n"
. "To: ".$recipients[$key][0]."\r\n"
. "CC: ".$ccList."\r\n"
. "Date: $dmy\r\n"
. "Subject: $subject\r\n"
. "MIME-Version: 1.0\r\n"
. "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"
. "\r\n\r\n"
. "--$boundary\r\n"
. "Content-Type: text/html;\r\n\tcharset=\"ISO-8859-1\"\r\n"
. "Content-Transfer-Encoding: 8bit \r\n"
. "\r\n\r\n"
. $body . "\r\n"
. "\r\n\r\n"
. "--$boundary\r\n"
. "Content-Transfer-Encoding: base64\r\n";
foreach($attachment as $attchURL){
$files = $_SERVER['DOCUMENT_ROOT'] . "/attachments/" . $attchURL;
$filename = substr($attchURL, strrpos($attchURL,"/")+1);
$ouv=fopen ("$files", "rb");$lir=fread ($ouv, filesize ("$files"));
fclose($ouv);
$attachments = chunk_split(base64_encode($lir));
$msg .= "Content-Disposition: attachment; filename=\"$filename\"\r\n" ;
$msg .= "\r\n" . $attachments . "\r\n";
}
$msg .= "\r\n\r\n\r\n"
. "--$boundary--\r\n\r\n";
imap_append($mbox,$authhost,($msg));
imap_close($mbox);
}
答案 0 :(得分:-1)
if ($mbox=imap_open( $authhost, $user, $pass))
{
$dmy=date("d-M-Y H:i:s");
$boundary = "------=" . md5(uniqid(rand()));
$msg .= "From: ".$from[0]."\r\n"
. "To: ".$recipients[$key][0]."\r\n"
. "CC: ".$ccList."\r\n"
. "Date: $dmy\r\n"
. "Subject: $subject\r\n"
. "MIME-Version: 1.0\r\n"
. "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"
. "\r\n\r\n"
. "--$boundary\r\n"
. "Content-Type: text/html;\r\n\tcharset=\"ISO-8859-1\"\r\n"
. "Content-Transfer-Encoding: 8bit \r\n"
. "\r\n\r\n"
. $body . "\r\n"
. "\r\n\r\n";
foreach($attachment as $attchURL){
$files = $_SERVER['DOCUMENT_ROOT'] . "/attachments/" . $attchURL;
$filename = substr($attchURL, strrpos($attchURL,"/")+1);
$ouv=fopen ("$files", "rb");$lir=fread ($ouv, filesize ("$files"));
fclose($ouv);
$attachments = chunk_split(base64_encode($lir));
$msg .= "--$boundary\r\n"
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment; filename=\"$filename\"\r\n" ;
$msg .= "\r\n" . $attachments . "\r\n";
}
$msg .= "\r\n\r\n\r\n"
. "--$boundary--\r\n\r\n";
imap_append($mbox,$authhost,($msg));
imap_close($mbox);
}