Support the ongoing development of Laravel.io →
Laravel JavaScript Mail

I'm trying to send an email with laravel. With this function I can send emails and attachments.

But when I try to send images, providers like gmail tend not to accept all types, for example:

<img src = "base64">

What I'm trying to deploy is sending these images as an inline attachment, but to no avail, this is my code.

$email_status = Mail::send([], [], function($message) use ($to_name,
$dest,$in_message,$name,$subj,$cc,$bcc,$files) {
        $message->to($dest, $to_name)
        ->subject($subj)->setBody($in_message,"text/html");
        if(!empty($cc)) $message->cc($cc);
        if(!empty($bcc)) $message->bcc($bcc);
        $message->from("email@gmail.com",$name);
        if(!empty($files)){
            foreach($files as $file) {
                $message->attach($file->getRealPath(), array(
                    'as' => $file->getClientOriginalName(),       
                    'mime' => $file->getMimeType())
                );
            }
        }
});

Okay, that works, but how to use Inline Attachments

In the body of the html I tried:

<img src="{{$message->embed($files[0]->getRealPath()) }}">
<img src="{{$message->embed($files[0]) }}">

I'm using files[0], because files is an object array of file type, sent by javascript. Object File

When this email arrives at its destination, and I inspect it, I have:

<img>
Last updated 3 years ago.

ngoquocdat liked this thread

1

Hey, I had several issues with images in my emails too, at the end I installed this package, Laravel Mail Auto Embed, that does everything for you and it works great.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.