我似乎無法找到這個PHP函數的問題,我寫的應該發送附件的電子郵件。我一直在努力掙扎。php發送電子郵件附件
function myMail($to, $subject, $mail_msg, $filename, $contentType){
$random_hash = md5(date('r', time()));
$headers = "From: [email protected]\r\nReply-To: ".$to;
$headers .= "\r\nContent-Type: ".$contentType.
"; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
ob_start();
echo "
--PHP-mixed-$random_hash
Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"
--PHP-alt-$random_hash
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit
$mail_msg
--PHP-alt-$random_hash
--PHP-mixed-$random_hash--
Content-Type: text/plain; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--PHP-mixed-$random_hash--
";
$message = ob_get_clean();
$mail_sent = @mail($to, $subject, $message, $headers);
return $mail_sent ? "Mail sent" : "Mail failed";
}
編輯的問題是,在郵件的消息與文件混合並作爲附件發送。
你不是說什麼行不通。 – 2010-06-22 12:02:33
包含整個輸出,包含頭文件(減去base64編碼文件) – Artefacto 2010-06-22 12:16:17