Skip to content

Commit

Permalink
Fixes to the Mailer
Browse files Browse the repository at this point in the history
LukeTowers committed Mar 1, 2022

Verified

This commit was signed with the committer’s verified signature.
joshcooper Josh Cooper
1 parent c94397f commit 27031ee
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions src/Mail/Mailer.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
use Illuminate\Mail\Mailer as MailerBase;
use Illuminate\Contracts\Mail\Mailable as MailableContract;
use Illuminate\Support\Collection;
use Illuminate\Mail\SentMessage;

/**
* Mailer class for sending mail.
@@ -144,41 +145,45 @@ public function send($view, array $data = [], $callback = null)
return;
}



// Next we will determine if the message should be sent. We give the developer
// one final chance to stop this message and then we will send it to all of
// its recipients. We will then fire the sent event for the sent message.
$symfonyMessage = $message->getSymfonyMessage();

$sentMessage = null;
if ($this->shouldSendMessage($symfonyMessage, $data)) {
$sentMessage = $this->sendSymfonyMessage($symfonyMessage);

$this->dispatchSentEvent($message, $data);

$sentMessage = new SentMessage($sentMessage);

/**
* @event mailer.send
* Fires after the message has been sent
*
* Example usage (logs the message):
*
* Event::listen('mailer.send', function ((\Winter\Storm\Mail\Mailer) $mailerInstance, (string) $view, (\Illuminate\Mail\Message) $message, (array) $data) {
* \Log::info("Message was rendered with $view and sent");
* });
*
* Or
*
* $mailerInstance->bindEvent('mailer.send', function ((string) $view, (\Illuminate\Mail\Message) $message, (array) $data) {
* \Log::info("Message was rendered with $view and sent");
* });
*
*/
$this->fireEvent('mailer.send', [$view, $message, $data]);
Event::fire('mailer.send', [$this, $view, $message, $data]);
$symfonySentMessage = $this->sendSymfonyMessage($symfonyMessage);

if ($symfonySentMessage) {
$sentMessage = new SentMessage($symfonySentMessage);

$this->dispatchSentEvent($sentMessage, $data);

/**
* @event mailer.send
* Fires after the message has been sent
*
* Example usage (logs the message):
*
* Event::listen('mailer.send', function ((\Winter\Storm\Mail\Mailer) $mailerInstance, (string) $view, (\Illuminate\Mail\Message) $message, (array) $data) {
* \Log::info("Message was rendered with $view and sent");
* });
*
* Or
*
* $mailerInstance->bindEvent('mailer.send', function ((string) $view, (\Illuminate\Mail\Message) $message, (array) $data) {
* \Log::info("Message was rendered with $view and sent");
* });
*
*/
$this->fireEvent('mailer.send', [$view, $message, $data]);
Event::fire('mailer.send', [$this, $view, $message, $data]);

return $sentMessage;
}
}

return $sentMessage;
}

/**

0 comments on commit 27031ee

Please sign in to comment.