I have a CKEditor 3.6.5 (revision 7647) field (on a CakePHP 2.2.1 site) where users paste print screen images (only works on Firefox). The html generated by the paste (button paste from word) is something like this:
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==" />
At a certain point I have to send by Email the html on these fields which should include the images.
Reading [base64-encoded-images-in-email-signatures][1] and [how-to-embed-images-in-email][2] I figured that the Email should have an attachment with the image.
My question is how can I transform the src of the image on a file? This way I intend to transform the HTML before send.
I have tried with success to attach a file with:
$data = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==');//file_get_contents('http://' . env('HTTP_HOST') . $fileInfo['url'] . '/disable-auth-key:' . Configure::read('Security.salt') . '.' . $fileInfo['ext']);
$handle = fopen(TMP . 'print_screen.png', 'w+');
fwrite($handle, $data);
fclose($handle);
$email = new CakeEmail(array(
'log' => true,
'config' => 'smtp',
'returnPath' => '[email protected]',
'from' => array('[email protected]' => 'APP'),
'to' => array('[email protected]' => 'Name'),
'emailFormat' => 'html',
'subject' => 'image test',
'domain' => '@uab.pt',
'attachments' => array(
'print_screen.png' => array(
'file' => TMP . 'print_screen.png',
'mimetype' => 'image/png',
'contentId' => 'Print-Screen-01'
)
)
));
$email->send('test|<img src="cid:print_screen.png@Print-Screen-01">|');
On GMail I have access to the attachment file but on the body no image. Where is the source
<div id=":85x">test|<img>|</div>
On Outlook, no attachments and the source is
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">test|<img src="cid:print_screen.png@Print-Screen-01">
I'm also open to other solutions that achieve the same result.
on the src attribute of the image tag the cid value should be I was using @.
The correct line of code
$email->send('test|<img src="cid:Print-Screen-01">|');