How to display logo in mail body using laravel

To display a logo in the mail body using Laravel, you can use the embed method provided by the Illuminate\Mail\Message class. Here's an example:

Step 1: Store the logo image

Store the logo image in a public directory, for example, public/images/logo.png.

Step 2: Create a mail view

Create a new mail view in resources/views/emails directory, for example, logo.blade.php. In this view, you can use the embed method to display the logo image:

<img src="cid:logo" alt="Logo">

The cid attribute specifies the content ID of the embedded image.

Step 3: Configure the mail

In your Laravel application, configure the mail settings in config/mail.php. Add the following code to the logo section:

'logo' => [
    'type' => 'image/png',
    'disposition' => 'inline',
    'filename' => 'logo.png',
    'content_id' => 'logo',
],

Step 4: Send the mail

In your controller or mail class, use the embed method to embed the logo image in the mail body:

use Illuminate\Mail\Message;
use Illuminate\Mail\Mailable;

class LogoMail extends Mailable
{
    public function build()
    {
        $message = (new Message())->embed('logo', public_path('images/logo.png'));

        return $message->subject('Logo Mail')
            ->view('emails.logo');
    }
}

In this example, we create a new Message instance and use the embed method to embed the logo image. We specify the content ID (logo) and the path to the logo image.

Step 5: Send the mail

Call the send method to send the mail:

LogoMail::send();

When you send the mail, the logo image will be embedded in the mail body, and it will be displayed as an inline image.

That's it! You should now be able to display a logo in the mail body using Laravel.