@@ -45,27 +45,24 @@ public function send(RawMessage $message, Envelope $envelope = null): void
45
45
return ;
46
46
}
47
47
48
- $ clonedMessage = clone $ message ;
49
-
50
- // When dispatching a message using messenger, we clear the context to prevent serialization errors
51
- if ($ clonedMessage instanceof TemplatedEmail) {
52
- $ clonedMessage ->context ([]);
53
- }
54
- $ clonedEnvelope = null !== $ envelope ? clone $ envelope : Envelope::create ($ clonedMessage );
55
-
56
48
$ stamps = [];
57
49
if (null !== $ this ->dispatcher ) {
58
50
// The dispatched event here has `queued` set to `true`; the goal is NOT to render the message, but to let
59
51
// listeners do something before a message is sent to the queue.
60
52
// We are using a cloned message as we still want to dispatch the **original** message, not the one modified by listeners.
61
53
// That's because the listeners will run again when the email is sent via Messenger by the transport (see `AbstractTransport`).
62
54
// Listeners should act depending on the `$queued` argument of the `MessageEvent` instance.
55
+ $ clonedMessage = clone $ message ;
56
+ $ clonedEnvelope = null !== $ envelope ? clone $ envelope : Envelope::create ($ clonedMessage );
63
57
$ event = new MessageEvent ($ clonedMessage , $ clonedEnvelope , (string ) $ this ->transport , true );
64
58
$ this ->dispatcher ->dispatch ($ event );
65
59
$ stamps = $ event ->getStamps ();
66
60
}
67
61
68
62
try {
63
+ if ($ message instanceof TemplatedEmail) {
64
+ $ message ->context ([]);
65
+ }
69
66
$ this ->bus ->dispatch (new SendEmailMessage ($ message , $ envelope ), $ stamps );
70
67
} catch (HandlerFailedException $ e ) {
71
68
foreach ($ e ->getNestedExceptions () as $ nested ) {
0 commit comments