From 0aae75388cef0a41931c491dfef7deb0a18fa101 Mon Sep 17 00:00:00 2001 From: trit Date: Wed, 23 Nov 2011 06:54:25 -0500 Subject: Added custom file name to attach(), updated _build_message to handle it --- system/libraries/Email.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'system/libraries/Email.php') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 7bde4c4fd..b898bae2a 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -38,7 +38,7 @@ * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/email.html */ -class CI_Email { +class CI_Email{ var $useragent = "CodeIgniter"; var $mailpath = "/usr/sbin/sendmail"; // Sendmail path @@ -418,9 +418,9 @@ class CI_Email { * @param string * @return void */ - public function attach($filename, $disposition = 'attachment') + public function attach($filepath, $filename=NULL, $disposition = 'attachment') { - $this->_attach_name[] = $filename; + $this->_attach_name[] = array($filepath, $filename); $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION)); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters return $this; @@ -1151,13 +1151,19 @@ class CI_Email { for ($i=0; $i < count($this->_attach_name); $i++) { - $filename = $this->_attach_name[$i]; - $basename = basename($filename); + $filepath = $this->_attach_name[$i][0]; + $basename = $this->_attach_name[$i][1]; + + if( ! $basename) + { + $basename = basename($filename); + } + $ctype = $this->_attach_type[$i]; - if ( ! file_exists($filename)) + if ( ! file_exists($filepath)) { - $this->_set_error_message('lang:email_attachment_missing', $filename); + $this->_set_error_message('lang:email_attachment_missing', $filepath); return FALSE; } @@ -1168,11 +1174,11 @@ class CI_Email { $h .= "Content-Transfer-Encoding: base64".$this->newline; $attachment[$z++] = $h; - $file = filesize($filename) +1; + $file = filesize($filepath) +1; - if ( ! $fp = fopen($filename, FOPEN_READ)) + if ( ! $fp = fopen($filepath, FOPEN_READ)) { - $this->_set_error_message('lang:email_attachment_unreadable', $filename); + $this->_set_error_message('lang:email_attachment_unreadable', $filepath); return FALSE; } -- cgit v1.2.3-24-g4f1b