Included the method to attach files.

This commit is contained in:
Juan Basso 2011-03-04 01:27:18 -03:00
parent df2fe579cd
commit ffaee3d760

View file

@ -784,7 +784,7 @@ class CakeEmail {
$this->_message = $message;
if (!empty($this->_attachments)) {
//$this->_attachFiles();
$this->_attachFiles();
}
if (!is_null($this->_boundary)) {
@ -954,6 +954,28 @@ class CakeEmail {
$this->_boundary = md5(uniqid(time()));
}
/**
* Attach files by adding file contents inside boundaries.
*
* @return void
*/
function _attachFiles() {
foreach ($this->_attachments as $filename => $file) {
$handle = fopen($file, 'rb');
$data = fread($handle, filesize($file));
$data = chunk_split(base64_encode($data)) ;
fclose($handle);
$this->_message[] = '--' . $this->_boundary;
$this->_message[] = 'Content-Type: application/octet-stream';
$this->_message[] = 'Content-Transfer-Encoding: base64';
$this->_message[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
$this->_message[] = '';
$this->_message[] = $data;
$this->_message[] = '';
}
}
/**
* Format the message by seeing if it has attachments.
*