Open linushstge opened 1 year ago
I was able to figure out that the error does not only occur in the mailables, but globally in the entire application. As soon as variables are assigned to any template, the existing variables are also applied to all following templates.
Example:
$template1 = view('mail.test',['example' => 'assigned to first template'])->render();
$template2 = view('mail.test')->render();
echo $template1;
// <pre>assigned to first template</pre> (expected)
echo $template2;
// <pre>assigned to first template</pre> (unexpected)
To fix this issue, all previous assignments have to be cleared for uncached template fetches as suggested in #87
In Version 6 and 7 there is an issue with assigned template variables in relation with the queue:work command. Instead of queue:listen queue:work does not always boot Laravel so the existing Smarty Instance is kept.
Steps to reproduce
Result in queue:listen: As expected, the variable gets only applied to the first mailable Result in queue:work: The variable is dumped in both templates
Example files
App/Mail/TestMail1.php
App/Mail/TestMail2.php
templates/mail/test.tpl
TestController.php
Required Changes
Smarty assignments have to be cleared on each Mailable.
In the current implementation, there is a risk that variables that are not overwritten by a second Mailable are erroneously transmitted in an email.
Notes
false
true
$variable
is applied to all further mailables (even if the template file name differs)