Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 36eeba7

Browse filesBrowse files
author
Guillaume Verstraete
committed
[Mailer] Fix addresses management in Sendgrid API payload
1 parent 3415224 commit 36eeba7
Copy full SHA for 36eeba7

File tree

Expand file treeCollapse file tree

2 files changed

+21
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-6
lines changed

‎src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Sendgrid/Tests/Transport/SendgridApiTransportTest.php
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridApiTransport;
16+
use Symfony\Component\Mime\Address;
1617
use Symfony\Component\Mime\Email;
1718
use Symfony\Contracts\HttpClient\HttpClientInterface;
1819
use Symfony\Contracts\HttpClient\ResponseInterface;
@@ -48,8 +49,8 @@ public function getTransportData()
4849
public function testSend()
4950
{
5051
$email = new Email();
51-
$email->from('foo@example.com')
52-
->to('bar@example.com')
52+
$email->from(new Address('foo@example.com', 'Ms. Foo Bar'))
53+
->to(new Address('bar@example.com', 'Mr. Recipient'))
5354
->bcc('baz@example.com')
5455
->text('content');
5556

@@ -73,12 +74,18 @@ public function testSend()
7374
'json' => [
7475
'personalizations' => [
7576
[
76-
'to' => [['email' => 'bar@example.com']],
77+
'to' => [[
78+
'email' => 'bar@example.com',
79+
'name' => 'Mr. Recipient',
80+
]],
7781
'subject' => null,
7882
'bcc' => [['email' => 'baz@example.com']],
7983
],
8084
],
81-
'from' => ['email' => 'foo@example.com'],
85+
'from' => [
86+
'email' => 'foo@example.com',
87+
'name' => 'Ms. Foo Bar',
88+
],
8289
'content' => [
8390
['type' => 'text/plain', 'value' => 'content'],
8491
],

‎src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,19 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
6363

6464
private function getPayload(Email $email, Envelope $envelope): array
6565
{
66-
$addressStringifier = function (Address $address) {return ['email' => $address->toString()]; };
66+
$addressStringifier = function (Address $address) {
67+
$stringified = ['email' => $address->getAddress()];
68+
69+
if ($address->getName()) {
70+
$stringified['name'] = $address->getName();
71+
}
72+
73+
return $stringified;
74+
};
6775

6876
$payload = [
6977
'personalizations' => [],
70-
'from' => ['email' => $envelope->getSender()->toString()],
78+
'from' => $addressStringifier($envelope->getSender()),
7179
'content' => $this->getContent($email),
7280
];
7381

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.