Skip to content

Commit

Permalink
Merge pull request #61 from stackkit/7.x-dev
Browse files Browse the repository at this point in the history
Use mail from name even if it was not specified
  • Loading branch information
marickvantuil authored Mar 24, 2024
2 parents 2816911 + c1b30e6 commit 29ac9f2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/EmailComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ public function send(): Email
(new MailableReader())->read($this);
}

if (! $this->email->from) {
$this->email->from = [
'address' => config('mail.from.address'),
'name' => config('mail.from.name'),
];
if (! is_array($this->email->from)) {
$this->email->from = [];
}

$this->email->from = [
'name' => $this->email->from['name'] ?? config('mail.from.name'),
'address' => $this->email->from['address'] ?? config('mail.from.address'),
];

$this->email->save();

$this->email->refresh();
Expand Down
2 changes: 1 addition & 1 deletion tests/MailableReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function it_extracts_the_from_address_and_or_name()

$this->assertTrue((bool) $email->from);
$this->assertEquals('marick@dolphiq.nl', $email->from['address']);
$this->assertEquals(null, $email->from['name']);
$this->assertEquals('Laravel', $email->from['name']);

$email = Email::compose()->mailable(
($this->mailable())
Expand Down
2 changes: 1 addition & 1 deletion tests/SenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function the_email_has_a_correct_from_email_and_from_name()
$this->artisan('email:send');
$from = reset($this->sent)->from;
$this->assertEquals('marick@dolphiq.nl', key($from));
$this->assertEquals(null, $from[key($from)]);
$this->assertEquals('From CI test', $from[key($from)]);
}

#[Test]
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ protected function getEnvironmentSetUp($app)
]);

$app['config']->set('mail.driver', 'log');

$app['config']->set('mail.from.name', 'Laravel');
}

public function createEmail($overwrite = [])
Expand Down

0 comments on commit 29ac9f2

Please sign in to comment.