diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index 250cde980a86..5ebeb0fedf1a 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -10,6 +10,7 @@ use Illuminate\Contracts\Queue\Factory as Queue; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Contracts\Support\Renderable; +use Illuminate\Contracts\Translation\HasLocalePreference; use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; use Illuminate\Support\Str; @@ -577,6 +578,10 @@ public function hasFrom($address, $name = null) */ public function to($address, $name = null) { + if (! $this->locale && $address instanceof HasLocalePreference) { + $this->locale($address->preferredLocale()); + } + return $this->setAddress($address, $name, 'to'); } diff --git a/tests/Integration/Mail/SendingMailWithLocaleTest.php b/tests/Integration/Mail/SendingMailWithLocaleTest.php index abdf299c9fff..8b307c058188 100644 --- a/tests/Integration/Mail/SendingMailWithLocaleTest.php +++ b/tests/Integration/Mail/SendingMailWithLocaleTest.php @@ -95,6 +95,11 @@ public function testLocaleIsSentWithModelPreferredLocale() $this->assertStringContainsString('esm', app('mailer')->getSymfonyTransport()->messages()[0]->toString() ); + + $mailable = new Mailable; + $mailable->to($recipient); + + $this->assertSame($recipient->email_locale, $mailable->locale); } public function testLocaleIsSentWithSelectedLocaleOverridingModelPreferredLocale()