在codeigniter Email類中,當我們將MIME類型作爲參數傳遞時,執行以下代碼。
$file_content =& $file; // buffered file
$this->_attachments[] = array(
'name' => array($file, $newname),
'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters
'type' => $mime,
'content' => chunk_split(base64_encode($file_content)),
'multipart' => 'mixed'
);
chunk_split(base64_encode($file_content))
將打破我們傳遞給$this->email->attach()
功能以base64文件。
讓我改變了代碼
$file_content =& $file; // buffered file
$file_content = ($this->_encoding == 'base64') ? $file_content : chunk_split(base64_encode($file_content));
現在附件數組:
$this->_attachments[] = array(
'name' => array($file, $newname),
'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters
'type' => $mime,
'content' => $file_content,
'multipart' => 'mixed'
);
現在,當我intialzed電子郵件:
$config['_bit_depths'] = array('7bit', '8bit','base64');
$config['_encoding'] = 'base64'
$this->load->library('email',$config);
可能是我做錯誤的方式,但它的作品。
$this->email->attach($base64,'attachment','report.pdf','application/pdf');
下載修改過的電子郵件類:
https://github.com/aqueeel/CI-Base64EmailAttach
有跡象表明,處理附件,HTML郵件等你,像SwiftMailer,PHPMailer的第三方電子郵件庫。 – bumperbox