Jul 15
0
Embed email logos in Laravel
It's nice to embed your logo in emails. When the logo file is embedded (or attached), it is then visible immediately for users that have enabled email privacy in their email clients - without having to click the "Show Inline Images" button.
I've customized the default Laravel email template quite a bit. You can do the same by running the php artisan vendor:publish --tag=laravel-mail command – the email view files show up in your vendor/email directory for you to modify.
However! In Laravel email templates, the $message variable that's usually used to embed images as attachments isn't available.
I first tried embedding it via the <img src="data:image/png;base64..."> method, but this does not work in Gmail.
So my solution was doing my own embedding by intercepting outgoing emails through the MessageSending listener.
Here's an example.
Simply place this file in the Listeners folder, adjust filenames, and add it as a listener for the MessageSending event.
After this, I can modify my header.php file:
And finally, my logo always shows up in all email clients - even those with email privacy or "Block Remote Content" enabled.