Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Mailer] Payload sent to Sendgrid doesn't include names #35182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridApiTransport;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
Expand Down Expand Up @@ -48,8 +49,8 @@ public function getTransportData()
public function testSend()
{
$email = new Email();
$email->from('[email protected]')
->to('[email protected]')
$email->from(new Address('[email protected]', 'Ms. Foo Bar'))
->to(new Address('[email protected]', 'Mr. Recipient'))
->bcc('[email protected]')
->text('content');

Expand All @@ -73,12 +74,18 @@ public function testSend()
'json' => [
'personalizations' => [
[
'to' => [['email' => '[email protected]']],
'to' => [[
'email' => '[email protected]',
'name' => 'Mr. Recipient',
]],
'subject' => null,
'bcc' => [['email' => '[email protected]']],
],
],
'from' => ['email' => '[email protected]'],
'from' => [
'email' => '[email protected]',
'name' => 'Ms. Foo Bar',
],
'content' => [
['type' => 'text/plain', 'value' => 'content'],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,19 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e

private function getPayload(Email $email, Envelope $envelope): array
{
$addressStringifier = function (Address $address) {return ['email' => $address->toString()]; };
$addressStringifier = function (Address $address) {
$stringified = ['email' => $address->getAddress()];

if ($address->getName()) {
$stringified['name'] = $address->getName();
}

return $stringified;
};

$payload = [
'personalizations' => [],
'from' => ['email' => $envelope->getSender()->toString()],
'from' => $addressStringifier($envelope->getSender()),
'content' => $this->getContent($email),
];

Expand Down