summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/libraries/Email.php26
-rw-r--r--user_guide_src/source/changelog.rst3
-rw-r--r--user_guide_src/source/libraries/email.rst18
3 files changed, 26 insertions, 21 deletions
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index b84518bbd..20eac72fc 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -731,8 +731,10 @@ class CI_Email {
$this->_set_error_message('lang:email_attachment_unreadable', $filename);
return FALSE;
}
+
$file_content = stream_get_contents($fp);
$mime = $this->_mime_types(pathinfo($filename, PATHINFO_EXTENSION));
+ fclose($fp);
}
else
{
@@ -746,7 +748,7 @@ class CI_Email {
'content' => chunk_split(base64_encode($file_content))
);
- fclose($fp);
+
return $this;
}
@@ -754,25 +756,29 @@ class CI_Email {
// --------------------------------------------------------------------
/**
- * Sets and return id of attachment (useful for attached inline pictures)
+ * Set and return id of attachment
+ *
+ * useful for attached inline pictures
*
- * @param string
- * @return string
+ * @param string $filename
+ * @return string
*/
public function attach_cid($filename)
{
- if($this->multipart != 'related')
+ if ($this->multipart !== 'related')
{
$this->multipart = 'related'; // Thunderbird need this for inline images
}
- foreach($this->_attachments as $ind => $attach)
+
+ for ($i = 0, $c = count($this->_attachments); $i < $c; $i++)
{
- if($attach['name'][0] == $filename)
+ if ($attach['name'][0] === $filename)
{
- $this->_attachments[$ind]['cid'] = uniqid(basename($this->_attachments[$ind]['name'][0]) . "@");
- return $this->_attachments[$ind]['cid'];
+ $this->_attachments[$ind]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@');
+ return $this->_attachments[$i]['cid'];
}
}
+
return FALSE;
}
@@ -1416,7 +1422,7 @@ class CI_Email {
.'name="'.$basename.'"'.$this->newline
.'Content-Disposition: '.$this->_attachments[$i]['disposition'].';'.$this->newline
.'Content-Transfer-Encoding: base64'.$this->newline
- .(!empty($this->_attachments[$i]['cid']) ? "Content-ID: <".$this->_attachments[$i]['cid'].">".$this->newline : '');
+ .(empty($this->_attachments[$i]['cid']) ? '' : 'Content-ID: <'.$this->_attachments[$i]['cid'].'>'.$this->newline);
$attachment[$z++] = $this->_attachments[$i]['content'];
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index e8dc880e8..34eff5d57 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -334,8 +334,7 @@ Release Date: Not Released
- Added custom filename to ``Email::attach()`` as ``$this->email->attach($filename, $disposition, $newname)``.
- Added possibility to send attachment as buffer string in ``Email::attach()`` as ``$this->email->attach($buffer, $disposition, $newname, $mime)``.
- - Email attachments are creating in function Email::attach() - it's faster for sending many emails with same attachments
- - Added method Email::attach_cid() returning CID which enables to embed an attachment to html.
+ - Added method ``Email::attach_cid()`` returning CID which enables to embed an attachment to html.
- Added dsn (delivery status notification) option.
- Renamed method _set_header() to set_header() and made it public to enable adding custom headers in the :doc:`Email Library <libraries/email>`.
- Successfully sent emails will automatically clear the parameters.
diff --git a/user_guide_src/source/libraries/email.rst b/user_guide_src/source/libraries/email.rst
index 90b71142b..274d88d46 100644
--- a/user_guide_src/source/libraries/email.rst
+++ b/user_guide_src/source/libraries/email.rst
@@ -277,15 +277,15 @@ $this->email->attach_cid()
::
- $filename = '/img/photo1.jpg';
- $this->email->attach($filename);
- foreach ($list as $address)
- {
- $this->email->to($address);
- $cid = $this->email->attach_cid($filename);
- $this->email->message('<img src='cid:". $cid ."' alt="photo1" />');
- $this->email->send();
- }
+ $filename = '/img/photo1.jpg';
+ $this->email->attach($filename);
+ foreach ($list as $address)
+ {
+ $this->email->to($address);
+ $cid = $this->email->attach_cid($filename);
+ $this->email->message('<img src='cid:". $cid ."' alt="photo1" />');
+ $this->email->send();
+ }
CID for each Email have to be create again to be unique.