Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append stylesheets in laravel email

Tags:

laravel

I'm trying to send an email when user submits a form in laravel. So in my Controller I have :

Mail::to($request->to)->send(new \App\Mail\ShareEbol());

And in my ShareEBOL class, in build method I have:

public function build()
{
    return $this->markdown('panel.reports.ebol');
}

And in my ebol.blade.php file I have:

@extends('layouts.app')

@section('content')

    <h2 class="my-custom-header"> Hello World </h2>
    <p class="my-custom-paragraph"> some text... </p>

@endsection

And in my layouts.app blade file I have appended some stylesheets :

<link href="{{asset('assets/css/custom.css')}}" rel="stylesheet" type="text/css" />

Email is sent successfuly, but the problem is css styles that I have included in custom.css are not applied in email. How can I fix this?

like image 597
eylay Avatar asked Aug 29 '21 19:08

eylay


People also ask

How to configure the template of Laravel mail?

The template of Laravel mail can be configured as follows, To configure the routes, create the route by writing the code to the web.php file. The controller file is created with the standard user-preferred name and it should be scripted along with the home controller code.

How to send mailables in a different locale in Laravel?

Laravel allows you to send mailables in a locale other than the request's current locale, and will even remember this locale if the mail is queued. To accomplish this, the Mail facade offers a locale method to set the desired language.

How to customize Swiftmailer message in Laravel?

SwiftMessage can be customized using withSwiftMessage method of Mailable base class: https://laravel.com/docs/8.x/mail#customizing-the-swiftmailer-message However you have to remember to do it every time you create a new “mailable” class. Some mail APIs require you to put a special header each time you send an email.

How to use tailwind CSS in Laravel e-mail?

The process for using Tailwind CSS in Laravel e-mails is a simple four-step proces: Create an e-mail template and use Tailwind CSS in the template. Create a separate CSS-file ( mail.css) and run Tailwind CSS with a separate config.


1 Answers

Steps to customize css - Markdown Mailables

It seems that you had created your custom ui. so I try to help based on your custom need.


Option 1:

  1. Create path html/themes. for example: resources/views/panel/reports/ebol/html/themes

  2. copy your custom.css to html/themes

  3. edit config/mail.php like below:

    ...
    
    'markdown' => [
     'theme' => 'custom', // custom.css
    
     'paths' => [
         resource_path('views/panel/reports/ebol'),
     ],
    

    ],

Now default theme for all markdowns will be custom.css


Option 2:

another option is to set the theme using $theme property of mailable class instead of setting that in config/mail.php

for example:

class ShareEbol extends Mailable
{
    use Queueable, SerializesModels;

    public $theme = 'custom'; // custom.css

...

Option 3:

another option is to use Mail Notifications that is well documented here : Laravel Mail Notifications

like image 180
Arash Younesi Avatar answered Sep 19 '22 09:09

Arash Younesi