From 2cf25d1055b1d4f063e861f0846a0d521da987e6 Mon Sep 17 00:00:00 2001 From: Jason Tan Date: Wed, 8 Jul 2020 11:11:49 -0500 Subject: [PATCH] [Mailer] Fix reply-to functionality in the SendgridApiTransport --- .../Transport/SendgridApiTransportTest.php | 26 +++++++++++++++++++ .../Transport/SendgridApiTransport.php | 7 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) 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 ab271d574c796..8bc68036cfa41 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 28eb76d25bf6b..cce616baedcc4 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)) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy