SimpleSoftwareIO / simple-qrcode

An easy-to-use PHP QrCode generator with first-party support for Laravel.
https://www.simplesoftware.io/simple-qrcode
MIT License
2.72k stars 383 forks source link

The body of "Symfony\Component\Mime\Part\TextPart" Error While Sending Mail #284

Open kiranrs opened 1 year ago

kiranrs commented 1 year ago

Hi, I'm facing this error after upgrading Laravel 8.65 to 9.52. It was working fine on Laravel 8 but afterupgrading to Laravel 9I'm getting this error. The body of "Symfony\Component\Mime\Part\TextPart" must be a string, a resource, or an instance of "Symfony\Component\Mime\Part\File" (got "Illuminate\Support\HtmlString").

This my HTML Code {!!$message->embedData(QrCode::size(200)->format('png')->generate('My Data'), 'QrCode.png', 'image/png')!!}

palmersoft-uk commented 1 year ago

I experienced the same issue, resolved by using the following code instead

<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('My Data')) !!} ">
chinleung commented 11 months ago

You need to convert the instance of HtmlString into string. I believe the return type of embedData has changed since the writing of the docs.

You can use something like this:

{!!$message->embedData(QrCode::size(200)->format('png')->generate('MyData')->toHtml(),'QrCode.png','image/png')!!}

I've added the ->toHtml() which will convert the HtmlString instance into string.