File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -253,7 +253,38 @@ public function render($view, array $data = [])
253
253
254
254
$ data ['message ' ] = $ this ->createMessage ();
255
255
256
- return $ this ->renderView ($ view ?: $ plain , $ data );
256
+ return $ this ->replaceEmbeddedAttachments (
257
+ $ this ->renderView ($ view ?: $ plain , $ data ),
258
+ $ data ['message ' ]->getSymfonyMessage ()->getAttachments ()
259
+ );
260
+ }
261
+
262
+ /**
263
+ * Replace the embedded image attachments with raw, inline image data for browser rendering.
264
+ *
265
+ * @param string $renderedView
266
+ * @param array $attachments
267
+ * @return string
268
+ */
269
+ protected function replaceEmbeddedAttachments (string $ renderedView , array $ attachments )
270
+ {
271
+ if (preg_match_all ('/<img.+?src=[ \'"]cid:([^ \'"]+)[ \'"].*?>/i ' , $ renderedView , $ matches )) {
272
+ foreach (array_unique ($ matches [1 ]) as $ image ) {
273
+ foreach ($ attachments as $ attachment ) {
274
+ if ($ attachment ->getFilename () === $ image ) {
275
+ $ renderedView = str_replace (
276
+ 'cid: ' .$ image ,
277
+ 'data: ' .$ attachment ->getContentType ().';base64, ' .$ attachment ->bodyToString (),
278
+ $ renderedView
279
+ );
280
+
281
+ break ;
282
+ }
283
+ }
284
+ }
285
+ }
286
+
287
+ return $ renderedView ;
257
288
}
258
289
259
290
/**
You can’t perform that action at this time.
0 commit comments