Laravel – Sending email with Logo in body

All we need is an easy explanation of the problem, so here it is.

I want to send an email attaching the logo in the email body. I am using Laravel. But whenever I am trying to attach an image, it is not showing in the body. Instead, it is sending as an attachment. Any suggestion or article link would be helpful for me

The result i am getting
Laravel - Sending email with Logo in body

Sample

Laravel - Sending email with Logo in body

Mailable

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class SubscribeMail extends Mailable
{
    use Queueable, SerializesModels;

    public $data;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->subject('Test Mail')->view('mails.subscribe');
    }
}

Template Body

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <img src="{{$message->embed('https://itecounsel.com/public/assets/images/logo.png')}}" style="max-width: 100px"/>
    {{$data['email']}} has subscribed
</body>
</html>

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You have syntax error i mean curly braces used twice ,remove that and try once

  <img src="{{$message->embed(asset('assets/images/logo.png'))}}"/>

Method 2

Can you try this.
<img src="{{$message->embed('/assets/images/logo.png')}}"/>

Method 3

After doing several research I found the solution. Wrapping the image into a table works for me

enter image description here

Code

    <div class="wrapper">
        <div class="container">
            <header class="header">
                <h2 class="header-text">ITEC - International Training and Education Counsel</h2>
            </header>

            <section class="body">
                <table class="info-table" cell-padding="5">
                    <thead>
                        <tr>
                            <th colspan="2">
                                <a href="https://www.google.com/url?sa=i&url=https%3A%2F%2Fen.m.wikipedia.org%2Fwiki%2FFile%3AOikya_Front_Logo.png&psig=AOvVaw1gZAn58ULm8UEoqIhPaGNC&ust=1622533229901000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCKDEirm18_ACFQAAAAAdAAAAABAP">
                                 <img src="https://itecounsel.com/public/assets/images/logo.png" alt="Image" style="width: 100px;">

                                </a>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><strong class="point">Student Name: </strong></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><strong class="point">Contact: </strong></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><strong class="point">Email: </strong></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><strong class="point">Nationality: </strong></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><strong class="point">Qualification: </strong></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><strong class="point">Relevant Work Exprience: </strong></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><strong class="point">Work Location: </strong></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><strong class="point">Designation: </strong></td>
                            <td></td>
                        </tr>
                    </tbody>
                </table>
            </section>
        </div>
    </div>

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply