diff --git a/src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiAsyncAwsTransportTest.php b/src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiAsyncAwsTransportTest.php index a5e48ef966819..517c112fa6193 100644 --- a/src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiAsyncAwsTransportTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiAsyncAwsTransportTest.php @@ -82,7 +82,7 @@ public function testSend() $this->assertSame('Hello!', $content['Content']['Simple']['Subject']['Data']); $this->assertSame('"Saif Eddin" ', $content['Destination']['ToAddresses'][0]); $this->assertSame('=?UTF-8?B?SsOpcsOpbXk=?= ', $content['Destination']['CcAddresses'][0]); - $this->assertSame('"Fabien" ', $content['FromEmailAddress']); + $this->assertSame('=?UTF-8?B?RmFiacOpbg==?= ', $content['FromEmailAddress']); $this->assertSame('Hello There!', $content['Content']['Simple']['Body']['Text']['Data']); $this->assertSame('Hello There!', $content['Content']['Simple']['Body']['Html']['Data']); $this->assertSame(['replyto-1@example.com', 'replyto-2@example.com'], $content['ReplyToAddresses']); @@ -103,7 +103,7 @@ public function testSend() $mail->subject('Hello!') ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin')) ->cc(new Address('jeremy@derusse.com', 'Jérémy')) - ->from(new Address('fabpot@symfony.com', 'Fabien')) + ->from(new Address('fabpot@symfony.com', 'Fabién')) ->text('Hello There!') ->html('Hello There!') ->replyTo(new Address('replyto-1@example.com'), new Address('replyto-2@example.com')) diff --git a/src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiAsyncAwsTransport.php b/src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiAsyncAwsTransport.php index 62adcf0d571d8..0413b059c42d2 100644 --- a/src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiAsyncAwsTransport.php +++ b/src/Symfony/Component/Mailer/Bridge/Amazon/Transport/SesApiAsyncAwsTransport.php @@ -53,7 +53,7 @@ protected function getRequest(SentMessage $message): SendEmailRequest $envelope = $message->getEnvelope(); $request = [ - 'FromEmailAddress' => $envelope->getSender()->toString(), + 'FromEmailAddress' => $this->stringifyAddress($envelope->getSender()), 'Destination' => [ 'ToAddresses' => $this->stringifyAddresses($this->getRecipients($email, $envelope)), ], @@ -114,15 +114,20 @@ private function getRecipients(Email $email, Envelope $envelope): array protected function stringifyAddresses(array $addresses): array { return array_map(function (Address $a) { - // AWS does not support UTF-8 address - if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) { - return sprintf('=?UTF-8?B?%s?= <%s>', - base64_encode($name), - $a->getEncodedAddress() - ); - } - - return $a->toString(); + return $this->stringifyAddress($a); }, $addresses); } + + protected function stringifyAddress(Address $a): string + { + // AWS does not support UTF-8 address + if (preg_match('~[\x00-\x08\x10-\x19\x7F-\xFF\r\n]~', $name = $a->getName())) { + return sprintf('=?UTF-8?B?%s?= <%s>', + base64_encode($name), + $a->getEncodedAddress() + ); + } + + return $a->toString(); + } }