Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Multiple cc, bcc and reply to recipients on mail notifications #23760

Merged
merged 2 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/Illuminate/Notifications/Channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@ protected function addressMessage($mailMessage, $notifiable, $notification, $mes

$mailMessage->to($this->getRecipients($notifiable, $notification, $message));

if ($message->cc) {
$mailMessage->cc($message->cc[0], Arr::get($message->cc, 1));
if (! empty($message->cc)) {
foreach ($message->cc as $cc) {
$mailMessage->cc($cc[0], Arr::get($cc, 1));
}
}

if ($message->bcc) {
$mailMessage->bcc($message->bcc[0], Arr::get($message->bcc, 1));
if (! empty($message->bcc)) {
foreach ($message->bcc as $bcc) {
$mailMessage->bcc($bcc[0], Arr::get($bcc, 1));
}
}
}

Expand All @@ -160,7 +164,9 @@ protected function addSender($mailMessage, $message)
}

if (! empty($message->replyTo)) {
$mailMessage->replyTo($message->replyTo[0], Arr::get($message->replyTo, 1));
foreach ($message->replyTo as $replyTo) {
$mailMessage->replyTo($replyTo[0], Arr::get($replyTo, 1));
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Notifications/Messages/MailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function from($address, $name = null)
*/
public function replyTo($address, $name = null)
{
$this->replyTo = [$address, $name];
$this->replyTo[] = [$address, $name];

return $this;
}
Expand All @@ -158,7 +158,7 @@ public function replyTo($address, $name = null)
*/
public function cc($address, $name = null)
{
$this->cc = [$address, $name];
$this->cc[] = [$address, $name];

return $this;
}
Expand All @@ -172,7 +172,7 @@ public function cc($address, $name = null)
*/
public function bcc($address, $name = null)
{
$this->bcc = [$address, $name];
$this->bcc[] = [$address, $name];

return $this;
}
Expand Down
51 changes: 45 additions & 6 deletions tests/Notifications/NotificationMailMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,56 @@

class NotificationMailMessageTest extends TestCase
{
public function setUp()
public function testTemplate()
{
$this->message = new MailMessage;
$message = new MailMessage;

$this->assertEquals('notifications::email', $message->markdown);

$message->template('notifications::foo');

$this->assertEquals('notifications::foo', $message->markdown);
}

public function testTemplate()
public function testCcIsSetCorrectly()
{
$message = new MailMessage;
$message->cc('test@example.com');

$this->assertSame([['test@example.com', null]], $message->cc);

$message = new MailMessage;
$message->cc('test@example.com')
->cc('test@example.com', 'Test');

$this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->cc);
}

public function testBccIsSetCorrectly()
{
$this->assertEquals('notifications::email', $this->message->markdown);
$message = new MailMessage;
$message->bcc('test@example.com');

$this->assertSame([['test@example.com', null]], $message->bcc);

$message = new MailMessage;
$message->bcc('test@example.com')
->bcc('test@example.com', 'Test');

$this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->bcc);
}

public function testReplyToIsSetCorrectly()
{
$message = new MailMessage;
$message->replyTo('test@example.com');

$this->assertSame([['test@example.com', null]], $message->replyTo);

$this->message->template('notifications::foo');
$message = new MailMessage;
$message->replyTo('test@example.com')
->replyTo('test@example.com', 'Test');

$this->assertEquals('notifications::foo', $this->message->markdown);
$this->assertSame([['test@example.com', null], ['test@example.com', 'Test']], $message->replyTo);
}
}