我有功能将带有附件的邮件发送到 Microsoft Exchange 服务器。我的问题是,当我想添加附件时,整个消息部分正在将我的文本添加到附件源。当我将附件保存到邮件的正文部分时,我的附件源会记录在电子邮件正文中,而不是创建附件。下面是我的来源。
$eol = "\r\n";
$boundary = md5(time());
$mail = "explame@explame.com";
$headers = "From: no-replay@explame.com".$eol;
$headers .= "MIME-Version: 1.0".$eol; //utworzenie headera wiadomosci
$headers .= "Content-type: multipart/alternative; charset=utf-8".$eol;
$headers .= "Message-ID:< TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$boundary."\"".$eol;
$headers .= "--$boundary".$eol;
$headers .= "Content-Type: text/plain; charset=utf-8".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol;
$headers .= "--$boundary--".$eol.$eol;
if ($file != ''){
$handle = fopen($file['tmp_name'], 'rb');
$f_content = fread($handle, $file['size']);
$attachment = chunk_split(base64_encode($f_content));
fclose($handle);
$content .= "--$boundary".$eol;
$content .= "Content-type: ".$file['type'].'; '.'name="'.$file['name'].'"'.$eol;
$content .= 'Content-Disposition: attachment; filename="'.$file['name'].'"'.$eol.$eol;
$content .= "Content-Transfer-Encoding: base64".$eol;
$content .= $attachment.$eol.$eol;
$content .= "--$boundary--".$eol.$eol;
}
mail($mail, 'title', $content, $headers)
我想我什么都试过了,但对我没有用。:(