summaryrefslogtreecommitdiffstats
path: root/system/libraries/Email.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Email.php')
-rw-r--r--system/libraries/Email.php42
1 files changed, 26 insertions, 16 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 8f383c939..48c3bf3ab 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -407,11 +407,11 @@ class CI_Email {
* @param string
* @return object
*/
- public function attach($filename, $disposition = '', $newname = NULL)
+ public function attach($filename, $disposition = '', $newname = NULL, $mime = '')
{
$this->_attach_name[] = array($filename, $newname);
- $this->_attach_type[] = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
$this->_attach_disp[] = empty($disposition) ? 'attachment' : $disposition; // Can also be 'inline' Not sure if it matters
+ $this->_attach_type[] = $mime;
return $this;
}
@@ -1049,29 +1049,39 @@ class CI_Email {
$filename = $this->_attach_name[$i][0];
$basename = (is_null($this->_attach_name[$i][1])) ? basename($filename) : $this->_attach_name[$i][1];
$ctype = $this->_attach_type[$i];
+ $file_content = '';
- if ( ! file_exists($filename))
+ if ($this->_attach_type[$i] == '')
{
- $this->_set_error_message('lang:email_attachment_missing', $filename);
- return FALSE;
- }
+ if ( ! file_exists($filename))
+ {
+ $this->_set_error_message('lang:email_attachment_missing', $filename);
+ return FALSE;
+ }
+
+ $file = filesize($filename) +1;
+ if ( ! $fp = fopen($filename, FOPEN_READ))
+ {
+ $this->_set_error_message('lang:email_attachment_unreadable', $filename);
+ return FALSE;
+ }
+
+ $ctype = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
+ $file_content = fread($fp, $file);
+ fclose($fp);
+ }
+ else
+ {
+ $file_content =& $this->_attach_content[$i];
+ }
$attachment[$z++] = "--".$this->_atc_boundary.$this->newline
. "Content-type: ".$ctype."; "
. "name=\"".$basename."\"".$this->newline
. "Content-Disposition: ".$this->_attach_disp[$i].";".$this->newline
. "Content-Transfer-Encoding: base64".$this->newline;
- $file = filesize($filename) +1;
-
- if ( ! $fp = fopen($filename, FOPEN_READ))
- {
- $this->_set_error_message('lang:email_attachment_unreadable', $filename);
- return FALSE;
- }
-
- $attachment[$z++] = chunk_split(base64_encode(fread($fp, $file)));
- fclose($fp);
+ $attachment[$z++] = chunk_split(base64_encode($file_content));
}
$body .= implode($this->newline, $attachment).$this->newline."--".$this->_atc_boundary."--";