Submitting Base64 Images Using Laravel

I use Laravel to send emails, and plain text works fine. However, I had a problem attaching images to email. Currently, images are stored in the database as Base64 Strings.

This is the code that invokes the Mail facade in Laravel:

            Mail::queue('emails.infraction', $data, function($message) use ($email){
            $message -> from($fromEmail, 'Blah);
            $message -> to($toEmail) -> subject('Testing');

        });

Basically, the $ data variable contains all the information that I will display in the sent HTML message. I can easily access variables when displaying them in an email, but I am having problems attaching base64 images to email.

This is what I have tried so far:

        Evidence of Intraction:</p>
            <?php 
                $elementCount  = count($photos);
                for($x=0; $x<$elementCount; $x++){
                    echo '<p style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; margin-left: 80px;">';
                    echo "<img src=" . $message->embedData($data['photos'][$x], 'Blah') . ">";
                    echo "</p>";
                }
            ?>

But, as you can see here, gmail does not correctly encode this rawDataString into an image:

laravel

, , . 64 .

?

Laravel Mail Documentation , :

laravel mailer

, . , base64 " " , , , php laravel mailer .

+1
1

:

$message->embedData(base64_decode($data['photos'][$x]), 'Blah')
+3

Source: https://habr.com/ru/post/1692867/


All Articles