-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[7.x] Add plain mail to notifications #33725
[7.x] Add plain mail to notifications #33725
Conversation
Thanks for the PR @Jubeki! |
Hey @Jubeki nice work on the PR! However, it is now impossible to send plain text only notifications. And this was possible before by doing this: public function toMail($notifiable)
{
return (new MailMessage)
->view([
'html' => null,
'text' => 'mail.test.plain',
]);
} @driesvints to me, this is unfortunately a breaking change. I've left some comments on the commit as to how it could be fixed. I'll try to write tests for this to make sure that my suggestions work and I'll submit a PR to fix this. |
Link to comments from @pawelmysior: f28bde3 @pawelmysior I don't think this is a breaking change since we didn't support text views officially before. The example you showed would definitely have been a workaround for it but nothing we intended to work like that. I do agree with you that it might be prudent to implement a way to only send text notifications as well. For not it might be best that you fix the framework at the version before this change and indeed feel free to send in a PR 👍 |
You're right, the example I show is definitely a bit of a hack :) calling it a breaking change was maybe a bit rush from me.
I'm not sure I understand correctly what you mean. What do you mean that I should fix the framework at the version before this change? Please elaborate. Thanks! |
Ah sorry, I explained badly: if you rely on the previous way of working you should set your framework version in your composer.json at v7.22.4 for now. |
Ah, yeah! I was thinking of the other meaning of "fix" :) I already did that. Thanks ;) |
I'm wondering where I got the idea of doing: // Notice the array in the `view` method is a number indexed array of view names
return (new MailMessage)
->view(['emails.html', 'emails.plain'], $viewData); This used to combine the HTML view and plain view in a single email. The framework/src/Illuminate/Notifications/Messages/MailMessage.php Lines 13 to 18 in 0c93bf3
When I now pass an array it will fail ofcourse because the view name is supposed to be a string:
Is this an unintended BC or was this never supposed to work? |
@stayallive I'm guessing #33803 by @pawelmysior fixes that? |
@driesvints no. Since the array of views is inside |
Ping @Jubeki @pawelmysior do any of you two know what we're missing here? |
Well this broke our stuff (already seems to be fixed in #33803, wish I saw that before I spent hours digging trying to find the issue). Semantic versioning but not really still, I see. I don't even understand this PR. I have been sending both HTML and text emails for notifications since day 1. Reverted to 7.22.4 and checked, both emails formats work fine. This PR is just adding some "sugar" to do plain text and broke anyone using plain text already. EDIT: actually the other PR doesn't fix anything either. |
@stayallive no your code was fine. That's how it has always worked for emails. This PR has broken that because before it just returned the array you defined which got set to [['emails.html', 'emails.plain'], null] and the "fix" it's sending ['html' => ['emails.html', 'emails.plain'], 'text' => null]`. This needs to be reverted. And the proper way to do it would be to not touch EDIT: Or do a check to see if |
@robclancy you're correct. This was indeed untested and undocumented but it seems it worked this way. I'm sending in a PR to revert all of this but keep the tests and refactor them to the previous way that things worked.
Like you said this was untested and undocumented which is why this slipped through. These things happen unfortunately from time to time. Sorry this broke something for you and @stayallive. We're trying to do our best to keep these things from happening. |
Here's the PR: #33816 |
Thanks @driesvints for reverting this, I think keeping it as it was before is a better approach that what was introduced in this PR and in my two subsequent ones. |
I just checked the mail documentation. The array way was part of the mail docs for 5.2 at least. The named keys I'm sure was also part of mail docs at some point (on my phone so just did a quick look). However the latest docs show a fluent way of doing it instead, that's where the main confusion has come from. So the mail docs (not just notification) should reference the array method. The reason we knew how to do text emails is because this is originally how mail just worked so naturally we just did it on notification views. |
@robclancy check. We can definitely look at also implementing a fluent way that covers the existing use cases. If anyone wants to try a PR for that that keeps the current tests passing we can merge that. |
Thanks @driesvints, there are definitely possibilities to have the old and the new work together but this was a bit too bluntly (nl: kort door de bocht) like this. Thanks for reverting. And thank you @robclancy for explaining it clearly 👍 |
This pull request introduces the possibility to add a plain version to an html mail which are send via notifications.
Tools like SpamAssassin give a lower score if no plain version is attached to an email. So it would be better to make it possible to attach a plain version to notifications.
It is also still possible to send pure html emails without a plain version.
#33699 as issue