From 5a98a3dda56f6167f8241a7bc7d1c8784d98ccf9 Mon Sep 17 00:00:00 2001 From: Matteo Mattei Date: Thu, 15 Mar 2012 12:00:44 +0100 Subject: Email class: move string_attach() to attach() and add documentation --- system/libraries/Email.php | 24 +++--------------------- user_guide_src/source/libraries/email.rst | 14 +++++++++++--- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/system/libraries/Email.php b/system/libraries/Email.php index aec4957de..df03eaaf6 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -83,7 +83,6 @@ class CI_Email { protected $_attach_name = array(); protected $_attach_type = array(); protected $_attach_disp = array(); - protected $_attach_source = array(); protected $_attach_content = array(); protected $_protocols = array('mail', 'sendmail', 'smtp'); protected $_base_charsets = array('us-ascii', 'iso-2022-'); // 7-bit charsets (excluding language suffix) @@ -173,7 +172,6 @@ class CI_Email { $this->_attach_name = array(); $this->_attach_type = array(); $this->_attach_disp = array(); - $this->_attach_source = array(); $this->_attach_content = array(); } @@ -410,27 +408,11 @@ class CI_Email { * @param string * @return object */ - public function attach($filename, $disposition = '', $newname = NULL) + public function attach($filename, $str = '', $mime = '', $disposition = '', $newname = NULL) { $this->_attach_name[] = array($filename, $newname); - $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); + $this->_attach_type[] = ($mime === '') ? $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)) : $mime; $this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters - $this->_attach_source[] = 'file'; - return $this; - } - - /** - * Assign string attachments - * - * @param string - * @return object - */ - public function string_attach($str, $filename, $mime, $disposition = 'attachment') - { - $this->_attach_name[] = $filename; - $this->_attach_type[] = $mime; - $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters - $this->_attach_source[] = 'string'; $this->_attach_content[] = $str; return $this; } @@ -1071,7 +1053,7 @@ class CI_Email { $ctype = $this->_attach_type[$i]; $file_content = ''; - if($this->_attach_source[$i] == 'file') + if ($this->_attach_content[$i] === '') { if ( ! file_exists($filename)) { diff --git a/user_guide_src/source/libraries/email.rst b/user_guide_src/source/libraries/email.rst index 27b704dae..d05439a77 100644 --- a/user_guide_src/source/libraries/email.rst +++ b/user_guide_src/source/libraries/email.rst @@ -228,10 +228,18 @@ use the function multiple times. For example:: $this->email->attach('/path/to/photo2.jpg'); $this->email->attach('/path/to/photo3.jpg'); -If you'd like to change the disposition or add a custom file name, you can use the second and third paramaters. To use the default disposition (attachment), leave the second parameter blank. Here's an example:: +$filename, $str = '', $mime = '', $disposition = '', $newname = NULL +If you need to use a buffer string instead of a real (physical) file you can use the +second and third parameters that are respectively the buffer and the mime-type:: + + $this->email->attach('report.pdf', $buffer, 'application/pdf'); + +If you'd like to change the disposition or add a custom file name, you can use the +fourth and fifth paramaters. To use the default disposition (attachment), leave the +fourth parameter blank. Here's an example:: - $this->email->attach('/path/to/photo1.jpg', 'inline'); - $this->email->attach('/path/to/photo1.jpg', '', 'birthday.jpg'); + $this->email->attach('/path/to/photo1.jpg', '', '', 'inline'); + $this->email->attach('/path/to/photo1.jpg', '', '', '', 'birthday.jpg'); $this->email->print_debugger() -- cgit v1.2.3-24-g4f1b