diff --git a/src/Illuminate/Mail/Events/MessageSending.php b/src/Illuminate/Mail/Events/MessageSending.php index 17bc25731dba..c9482542271c 100644 --- a/src/Illuminate/Mail/Events/MessageSending.php +++ b/src/Illuminate/Mail/Events/MessageSending.php @@ -4,6 +4,13 @@ class MessageSending { + /** + * The message data. + * + * @var array + */ + public $data; + /** * The Swift message instance. * @@ -14,11 +21,13 @@ class MessageSending /** * Create a new event instance. * - * @param \Swift_Message $message + * @param \Swift_Message $message + * @param array $data * @return void */ - public function __construct($message) + public function __construct($message, $data = []) { $this->message = $message; + $this->data = $data; } } diff --git a/src/Illuminate/Mail/Events/MessageSent.php b/src/Illuminate/Mail/Events/MessageSent.php index 8af4a0e93388..50973d81aad2 100644 --- a/src/Illuminate/Mail/Events/MessageSent.php +++ b/src/Illuminate/Mail/Events/MessageSent.php @@ -4,6 +4,13 @@ class MessageSent { + /** + * The message data. + * + * @var array + */ + public $data; + /** * The Swift message instance. * @@ -15,10 +22,12 @@ class MessageSent * Create a new event instance. * * @param \Swift_Message $message + * @param array $data * @return void */ - public function __construct($message) + public function __construct($message, $data = []) { $this->message = $message; + $this->data = $data; } } diff --git a/src/Illuminate/Mail/Mailer.php b/src/Illuminate/Mail/Mailer.php index f6508bc8744b..660834a14f27 100755 --- a/src/Illuminate/Mail/Mailer.php +++ b/src/Illuminate/Mail/Mailer.php @@ -231,10 +231,10 @@ public function send($view, array $data = [], $callback = null) // its recipients. We will then fire the sent event for the sent message. $swiftMessage = $message->getSwiftMessage(); - if ($this->shouldSendMessage($swiftMessage)) { + if ($this->shouldSendMessage($swiftMessage, $data)) { $this->sendSwiftMessage($swiftMessage); - $this->dispatchSentEvent($message); + $this->dispatchSentEvent($message, $data); } } @@ -458,16 +458,17 @@ protected function sendSwiftMessage($message) * Determines if the message can be sent. * * @param \Swift_Message $message + * @param array $data * @return bool */ - protected function shouldSendMessage($message) + protected function shouldSendMessage($message, $data = []) { if (! $this->events) { return true; } return $this->events->until( - new Events\MessageSending($message) + new Events\MessageSending($message, $data) ) !== false; } @@ -475,13 +476,14 @@ protected function shouldSendMessage($message) * Dispatch the message sent event. * * @param \Illuminate\Mail\Message $message + * @param array $data * @return void */ - protected function dispatchSentEvent($message) + protected function dispatchSentEvent($message, $data = []) { if ($this->events) { $this->events->dispatch( - new Events\MessageSent($message->getSwiftMessage()) + new Events\MessageSent($message->getSwiftMessage(), $data) ); } }