Skip to content

Commit

Permalink
Merge pull request #10 from timkelty/toMail-multiple
Browse files Browse the repository at this point in the history
Allow toMail channel to accept an array for sending multiple emails.
  • Loading branch information
Rias authored Jun 26, 2018
2 parents 653c94c + 16fd72f commit 4f3c5e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ return [

If a notification supports being sent as an email, you should define a `toMail` method on the notification class. This method will receive a `$notifiable` object that contains everything you defined in your `via` method.

The `toMail` function should return a `craft\mail\Message` instance. Let's take a look at an example toMail method:
The `toMail` function should return a `craft\mail\Message` instance. You may also return an array of `craft\mail\Message` instances if you wish to send multiple emails. Let's take a look at an example toMail method:

```php
public function toMail($notifiable)
Expand Down
13 changes: 8 additions & 5 deletions src/channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ class MailChannel
*/
public function send(string $notifiable, Notification $notification)
{
$message = $notification->toMail($notifiable);
$channelResult = $notification->toMail($notifiable);
$messages = is_array($channelResult) ? $channelResult : [$channelResult];

if (! $message instanceof Message) {
throw new \Exception("Message needs to be an instance of craft\mail\Message");
}
foreach ($messages as $message) {
if (! $message instanceof Message) {
throw new \Exception("Message needs to be an instance of craft\mail\Message");
}

$message->send();
$message->send();
}
}
}

0 comments on commit 4f3c5e8

Please sign in to comment.