CodeIgniter Forums

Full Version: CI3 inline images in email using buffer string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()?
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.