mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Included the method to attach files.
This commit is contained in:
parent
df2fe579cd
commit
ffaee3d760
1 changed files with 23 additions and 1 deletions
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue