Skip to content

Commit ffaee3d

Browse files
committed
Included the method to attach files.
1 parent df2fe57 commit ffaee3d

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/Cake/Network/CakeEmail.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ public function send($content = null) {
784784
$this->_message = $message;
785785

786786
if (!empty($this->_attachments)) {
787-
//$this->_attachFiles();
787+
$this->_attachFiles();
788788
}
789789

790790
if (!is_null($this->_boundary)) {
@@ -954,6 +954,28 @@ function _createboundary() {
954954
$this->_boundary = md5(uniqid(time()));
955955
}
956956

957+
/**
958+
* Attach files by adding file contents inside boundaries.
959+
*
960+
* @return void
961+
*/
962+
function _attachFiles() {
963+
foreach ($this->_attachments as $filename => $file) {
964+
$handle = fopen($file, 'rb');
965+
$data = fread($handle, filesize($file));
966+
$data = chunk_split(base64_encode($data)) ;
967+
fclose($handle);
968+
969+
$this->_message[] = '--' . $this->_boundary;
970+
$this->_message[] = 'Content-Type: application/octet-stream';
971+
$this->_message[] = 'Content-Transfer-Encoding: base64';
972+
$this->_message[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
973+
$this->_message[] = '';
974+
$this->_message[] = $data;
975+
$this->_message[] = '';
976+
}
977+
}
978+
957979
/**
958980
* Format the message by seeing if it has attachments.
959981
*

0 commit comments

Comments
 (0)