diff --git a/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php b/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php index ab271d574c79..8bc68036cfa4 100644 --- a/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php +++ b/src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php @@ -166,4 +166,30 @@ public function testCustomHeader() $this->assertArrayHasKey('foo', $payload['headers']); $this->assertEquals('bar', $payload['headers']['foo']); } + + public function testReplyTo() + { + $from = 'from@example.com'; + $to = 'to@example.com'; + $replyTo = 'replyto@example.com'; + $email = new Email(); + $email->from($from) + ->to($to) + ->replyTo($replyTo) + ->text('content'); + $envelope = new Envelope(new Address($from), [new Address($to)]); + + $transport = new SendgridApiTransport('ACCESS_KEY'); + $method = new \ReflectionMethod(SendgridApiTransport::class, 'getPayload'); + $method->setAccessible(true); + $payload = $method->invoke($transport, $email, $envelope); + + $this->assertArrayHasKey('from', $payload); + $this->assertArrayHasKey('email', $payload['from']); + $this->assertSame($from, $payload['from']['email']); + + $this->assertArrayHasKey('reply_to', $payload); + $this->assertArrayHasKey('email', $payload['reply_to']); + $this->assertSame($replyTo, $payload['reply_to']['email']); + } } diff --git a/src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php b/src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php index 28eb76d25bf6..cce616baedcc 100644 --- a/src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php +++ b/src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php @@ -93,11 +93,16 @@ private function getPayload(Email $email, Envelope $envelope): array if ($emails = array_map($addressStringifier, $email->getBcc())) { $personalization['bcc'] = $emails; } + if ($emails = array_map($addressStringifier, $email->getReplyTo())) { + // Email class supports an array of reply-to addresses, + // but SendGrid only supports a single address + $payload['reply_to'] = $emails[0]; + } $payload['personalizations'][] = $personalization; // these headers can't be overwritten according to Sendgrid docs - // see https://developers.pepipost.com/migration-api/new-subpage/email-send + // see https://sendgrid.api-docs.io/v3.0/mail-send/mail-send-errors#-Headers-Errors $headersToBypass = ['x-sg-id', 'x-sg-eid', 'received', 'dkim-signature', 'content-transfer-encoding', 'from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'reply-to']; foreach ($email->getHeaders()->all() as $name => $header) { if (\in_array($name, $headersToBypass, true)) {
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: