Skip to content

Commit

Permalink
Included the method to attach files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 13, 2011
1 parent df2fe57 commit ffaee3d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/Cake/Network/CakeEmail.php
Expand Up @@ -784,7 +784,7 @@ public function send($content = null) {
$this->_message = $message;

if (!empty($this->_attachments)) {
//$this->_attachFiles();
$this->_attachFiles();
}

if (!is_null($this->_boundary)) {
Expand Down Expand Up @@ -954,6 +954,28 @@ function _createboundary() {
$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.
*
Expand Down

0 comments on commit ffaee3d

Please sign in to comment.