jdavidbakr / mail-tracker

Package for Laravel to inject tracking code into outgoing emails.
MIT License
575 stars 129 forks source link

[6.0.3] Inline embedded images cause exception #177

Closed novelnet closed 2 years ago

novelnet commented 2 years ago

I get the following error when sending mails with inline embedded images: Call to undefined method Symfony\\Component\\Mime\\Part\\Multipart\\RelatedPart::getBody()

Example: <img src="{{ $message->embed(storage_path('app/mail-inline-attachments/youtubecirclecolored.png')) }}">

The image source gets automatically base64 encoded.

jdavidbakr commented 2 years ago

I tried to make a test case for this but can't figure out how to get it to be called. Can you give more context about where the $message variable is coming from, and perhaps look at the tests and put here a way to compose a message that calls $message->embed()?

novelnet commented 2 years ago

@jdavidbakr thank you! I made an example test for an inline embedded image which is working when disabling the mail-tracker by adding: ->withSymfonyMessage(function ($message) { $message->getHeaders()->addTextHeader('X-No-Track', Str::random(10)); })

To embed an inline image, use the embed method on the $message variable within your email template. Laravel automatically makes the $message variable available to all of your email templates, so you don't need to worry about passing it in manually:

https://laravel.com/docs/master/mail#inline-attachments

jdavidbakr commented 2 years ago

Thanks @novelnet - that was what I needed. Fixed in https://github.com/jdavidbakr/mail-tracker/releases/tag/6.0.4

novelnet commented 2 years ago

Thanks! :)