在 codeigniter 电子邮件类中,当我们将 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'
);
现在,当我使用以下命令初始化电子邮件时:
$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