The reason why the first method doesn't work is that the email client doesn't have access to the public folder of your Laravel application. Therefore, it cannot load the image from the URL.
The second method works because you are attaching the image to the email, and then referencing it using the cid (Content-ID) in the email body. This way, the email client can load the image from the attachment.
If you want to use the first method, you can encode the image as base64 and embed it directly in the email body. Here's an example:
// MyMail.php
$image = base64_encode(file_get_contents(public_path('images/my_image.png')));
return $this->from($from, "From title")
->subject("Subject")
->markdown("email_file")
->with(['image' => $image]);
// email_file.blade.php
<img src="data:image/png;base64,{{ $image }}" alt="My Image">
In this example, we're encoding the image as base64 and passing it to the email view using the with method. Then, in the email view, we're embedding the image directly in the src attribute using the data URI scheme.
Note that embedding images directly in the email body can increase the email size and affect deliverability. It's generally recommended to use attachments or external images hosted on a CDN.