• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI3 inline images in email using buffer string

#1
Good day,
I have a hard time adding a buffer string as inline image in an HTML email. 
Code:
$this->email->attach( $bin, 'inline', $filename, 'image/png' )

The command
Code:
$this->email->attachment_cid( $filename )
returns FALSE.

I looked into the Email library, function attachment_cid() and it turns out that buffered images have two filenames. The first one is gibberish, the second one is the actual filename. But the function checks only the first name and because that one's different from the chosen filename the function thinks there's no attachment of that name and returns FALSE.

Is this a bug in the function attachment_cid()?
Reply

#2
Just for reference, I extended the Email class with a custom method to be used with buffer strings:
Code:
    public function buffered_attachment_cid($filename)
    {
        for ($i = 0, $c = count($this->_attachments); $i < $c; $i++)
        {

            for ( $j = 0, $n = count( $this->_attachments[$i]['name'] ); $j < $n; $j++ )
            {
                if ($this->_attachments[$i]['name'][$j] === $filename)
                {
                    $this->_attachments[$i]['multipart'] = 'related';
                    $this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][$j]).'@');
                    return $this->_attachments[$i]['cid'];
                }
            }
        }

        return FALSE;
    }
This one handles inline buffer string images correctly.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.