[英]Base64 encoded excel file not decoding in email attachments
我正在創建一個excel文件並將其附加在電子郵件中。 電子郵件發送時附帶了excel文件,但是內容都被掩蓋了(N¬ŠÆ› j×!êh®×è®Ø^¥êè‰ÚzzMy¶9×Í´×)。
$sFileName = "BatchReport".date("Y-m-d");
$eContent = chunk_split(base64_encode(file_get_contents(WP_PLUGIN_DIR."/cs-cart/includes/excel/".$sFileName.".xls")));
$sUniqueID = md5(uniqid(time()));
$sHeaders = "From: " . (($sFrom) ? $sFrom : "Cervid Solutions <admin@" . str_replace("www.","",$_SERVER["HTTP_HOST"]) . ">") . "\n" .
"MIME-Version: 1.0\n" .
"Content-Type: multipart/mixed; boundary=".$sUniqueID."\n\n" .
"This is a multi-part message in MIME format.\r\n" .
"--".$sUniqueID."\r\n" .
"Content-Type: text/plain; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n" .
$sMessage."\r\n\r\n" .
"--".$sUniqueID."\r\n" .
"Content-Type: application/octet-stream; name=".$sFileName.".xls"."\n" .
"Content-Transfer-Encoding: base64\r\n" .
"Content-Disposition: attachment; filename=".$sFileName.".xls"."\r\n\r\n" .
$eContent."\r\n\r\n" .
"--".$sUniqueID."--";
wp_mail($sTo, $sSubject, $sMessage, $sHeaders);
我見過其他人使用相同的代碼,但是對於正確解碼文件內容似乎沒有相同的問題。 我究竟做錯了什么?
在使用wp_mail()
您不應該滾動自己的附件處理。
https://codex.wordpress.org/Function_Reference/wp_mail
wp_mail( $to, $subject, $message, $headers, $attachments )
您需要根據文檔添加附件。
在您的情況下:
$attachments = array(WP_PLUGIN_DIR."/cs-cart/includes/excel/".$sFileName.".xls");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.