diff --git a/lib/Cake/Network/CakeEmail.php b/lib/Cake/Network/CakeEmail.php index db8d5413108..23d53e6bca0 100644 --- a/lib/Cake/Network/CakeEmail.php +++ b/lib/Cake/Network/CakeEmail.php @@ -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)) { @@ -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. *