Cms: Mail Notifications unstyled

Created on 27 Oct 2020  Â·  26Comments  Â·  Source: statamic/cms

Bug Description

How to Reproduce

composer create-project --prefer-dist statamic/statamic test
php artisan make:notification TestNotification

...set up mail sending for mailtrap and add in default from address to .env

Illuminate\Support\Facades\Notification::route(
    'mail',
    '[email protected]'
)->notify(new App\Notifications\TestNotification());

...then do the same but using laravel new test

Extra Detail

Result from new statamic project:

Screenshot 2020-10-27 at 11 39 20

Result from new laravel 8.11.2 project:

Screenshot 2020-10-27 at 11 39 25

Environment

Statamic 3.0.20 Solo
Laravel 8.11.2
PHP 7.4.8
No addons installed
bug laravel

Most helpful comment

I've looked into this a little more.

There's a simpler workaround:

In config/mail.php, change theme from default to mail::themes.default.
You don't need to publish anything, etc.

I'll work out a real fix for Laravel.

All 26 comments

Guessing that Statamic doesn't "register" that theme folder?

This bug still exists in statamic/cms 3.0.22 - any reason why this is closed?

It's not closed?
image

Sorry man - I mistook the Closed tag in the #2760 issue.

My bad. Many thanks

Just stumbled across this bug in a non-Statamic app so posting my solution here just in case it helps anyone.

I had the file ./resources/views/default.blade.php - if I rename this I get the styling back.

Somehow this must be overriding the markdown email's default theme layout.

Thanks for the tip @mikefrancis .

I don't have that view, but I do have the statamic standard resources/views/default.antlers.html

Can you clarify what renaming action you actually did?

@admench I just renamed ./resources/views/default.blade.php to ./resources/views/something.blade.php and updated any child views that were extending the default view from:

@extends('default')

to:

@extends('something')

Yes I can confirm this fixes the styling issue with Notifications.

@jasonvarga can you possibly investigate this possible naming convention clash?

New notification after renaming default.antlers.html to main.antlers.html:

Screenshot_2020-11-03_at_08_35_51

Looks like the only place in the Laravel codebase that mentions default in the context of emails/notifications is in this file.

I've had a similar look at the Statamic codebase but couldn't find anything with default coded in, again with the context of mail.

This issue has not had recent activity and has been marked as stale — by me, a robot. Simply reply to keep it open and send me away. If you do nothing, I will close it in a week. I have no feelings, so whatever you do is fine by me.

Someone just ran into this same issue on the Discord this afternoon so I've re-opened. Link to conversation

Yep, still an issue indeed in 3.0.42.

I'll hopefully have time to look at this over the next couple of days, got a project where it's pretty important the notification styles work. 😅

I think this stale bot should be removed. It keeps closing issues that is not fixed yet.

I forgot to mention that it is working for v2 updates to V3

Just managed to replicate and I think I've figured out why it's trying to find a default view.

Essentially, Laravel has a concept of themes for its emails so you can customise the CSS & HTML in your emails. The default theme is default.

Laravel tries to find a view called default, the first one it can find is the one in resources/views/default.antlers.html, hence why it uses that view instead.

A workaround for now would be to create your own mail theme, there's documentation on that over in the Laravel docs.

Make sure to change the theme in your config/mail.php file.

Thanks for investigating.

@jackmcdade this seems to be something that should be in the docs.

@duncanmcclean Thanks for looking into it. On a V2 upgrade to V3 I have a default.antlers.html and it's still working. I get the styling correctly.

@duncanmcclean Thanks for looking into it. On a V2 upgrade to V3 I have a default.antlers.html and it's still working. I get the styling correctly.

That's weird, I'm guessing it's in the default place (resources/views) and theme is set to default in your config/mail.php?

Yeah - I tried finding the difference between the two setups yesterday.

https://share.getcloudapp.com/p9u8GeJe

Yeah - I tried finding the difference between the two setups yesterday.

https://share.getcloudapp.com/p9u8GeJe

Hmm, that's strange. I'm not sure why that would be happening.

Did you manage to get the new mail theme working?

Did you manage to get the new mail theme working?

Yeah, we're using one anyway on this project.

@duncanmcclean I just ran into this myself. Seems like the workaround is:

  1. php artisan vendor:publish --tag=laravel-mail
  2. Rename default.css to your new theme name. ie.theme-name.css
  3. Set the theme to your theme name in /config/mail.php 'theme' => 'theme-name'

I've looked into this a little more.

There's a simpler workaround:

In config/mail.php, change theme from default to mail::themes.default.
You don't need to publish anything, etc.

I'll work out a real fix for Laravel.

I PR'd a fix to Laravel. Once the next laravel/framework release is tagged you should be able to composer update and it'll be fixed. (Assuming you're using Laravel 8)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robdekort picture robdekort  Â·  3Comments

filipac picture filipac  Â·  4Comments

jimblue picture jimblue  Â·  3Comments

aerni picture aerni  Â·  3Comments

philippgrimm picture philippgrimm  Â·  3Comments