Laravel 5.4^ - How to customize notification email layout?

前端 未结 8 930
生来不讨喜
生来不讨喜 2020-12-01 08:07

I am trying to customize the HTML email layout that is used when sending notifications via email.

I have published both the mail and notification views.

相关标签:
8条回答
  • 2020-12-01 08:24

    Make sure to have the right configuration in your config/mail.php :

    'markdown' => [
        'theme' => 'default',
        'paths' => [
            resource_path('views/vendor/mail'),
        ]
    ],
    
    0 讨论(0)
  • 2020-12-01 08:29

    @Brian You can just make change to the @component directives in your template file to use your custom templates. For example:

    Replace @component('mail::message') with @component('vendor.mail.html.message'), assuming your template is located at /resources/views/vendor/mail/html/message.blade.php

    0 讨论(0)
  • 2020-12-01 08:30

    Run this command

    php artisan vendor:publish --tag=laravel-notifications
    php artisan vendor:publish --tag=laravel-mail
    

    update for laravel 5.7+

    php artisan vendor:publish
    

    and then you will get:

      [<number>] Tag: laravel-mail
      [<number>] Tag: laravel-notifications
    

    and then just type in that number in front to publish the file for editing


    and then in

    /resources/views/vendor/mail/html/
    

    you can edit all the components and customize anything you want. For example i have edited the sentence "All rights reserved". to "All test reserved" at the bottom of that image inside this file:

    /resources/views/vendor/mail/html/message.blade.php
    

    and this is what i got:

    0 讨论(0)
  • 2020-12-01 08:32

    Laravel 5.8

    I found email layout in file -> vendor/laravel/framework/src/Illuminate/Mail/resources/views/html/layout.blade.php.

    Like I don't use markdown to send my emails, i need of layout default of laravel (yes, because i want :)).

    What i did? I sent for me email for me of reset password, saved the email like html and then copied html to my editor and it ready to changes \o/.

    0 讨论(0)
  • 2020-12-01 08:35

    You are making email based on component @component('mail::message') This is a default and this is only one described in documentation. This component does not allow you to modify header. However if you look into it's file,

    \vendor\laravel\framework\src\Illuminate\Mail\resources\views\markdown\message.blade.php
    

    you will see that it uses another component @component('mail::layout'),

    Just copy content of message.blade.php file into your .blade.php and replace {{ $slot }} with what you had in your file before.

    And now you have all the flexibility in your file.

    Plus

    if you want to modify styles, go to file \config\mail.php

    and change markdown section like so

    'markdown' => [
        'theme' => 'default0',
    
        'paths' => [
            resource_path('views/vendor/mail'),
            base_path('resources/views/emails/vendor'),            
        ],
    ],
    

    In this case I replaced default theme with my own \resources\views\emails\vendor\html\themes\default0.css

    or, if you don't want customising paths - put your default0.css into /resources/views/vendor/mail/html/themes - it is a default path and you don't need to mention it.

    Tested on Laravel 5.7

    0 讨论(0)
  • 2020-12-01 08:37

    Do NOT do what is suggested here.

    This works. Just remember that you should edit the templates contained in the 'vendor/mail/html' folder AND NOT the contents of the 'vendor/mail/markdown' folder, unless of course you are using markdown instead of the line() / greeting() email building functions

    Instead, run the artisan commands and then edit the generated files in your resources folder that you end up with. Never overwrite the vendor files, as if you are working on a local version, then push it to a live server and run composer install, you will not have those changes anymore.

    Laravel's inheritance allows you to easily overwrite pre-defined methods and files, so take advantage of that for cleaner version control and better ability to roll back changes to core functionality.

    0 讨论(0)
提交回复
热议问题