|
17 | 17 | use Symfony\Component\Mailer\SentMessage; |
18 | 18 | use Symfony\Component\Mailer\Transport\AbstractApiTransport; |
19 | 19 | use Symfony\Component\Mime\Email; |
| 20 | +use Symfony\Component\Mime\NamedAddress; |
20 | 21 | use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
21 | 22 | use Symfony\Contracts\HttpClient\HttpClientInterface; |
22 | 23 | use Symfony\Contracts\HttpClient\ResponseInterface; |
@@ -75,11 +76,15 @@ private function getPayload(Email $email, Envelope $envelope): array |
75 | 76 | 'html' => $email->getHtmlBody(), |
76 | 77 | 'text' => $email->getTextBody(), |
77 | 78 | 'subject' => $email->getSubject(), |
78 | | - 'from_email' => $envelope->getSender()->toString(), |
| 79 | + 'from_email' => $envelope->getSender()->getAddress(), |
79 | 80 | 'to' => $this->getRecipients($email, $envelope), |
80 | 81 | ], |
81 | 82 | ]; |
82 | 83 |
|
| 84 | + if ($envelope->getSender() instanceof NamedAddress) { |
| 85 | + $payload['message']['from_name'] = $envelope->getSender()->getName(); |
| 86 | + } |
| 87 | + |
83 | 88 | foreach ($email->getAttachments() as $attachment) { |
84 | 89 | $headers = $attachment->getPreparedHeaders(); |
85 | 90 | $disposition = $headers->getHeaderBody('Content-Disposition'); |
@@ -119,10 +124,16 @@ protected function getRecipients(Email $email, Envelope $envelope): array |
119 | 124 | $type = 'cc'; |
120 | 125 | } |
121 | 126 |
|
122 | | - $recipients[] = [ |
123 | | - 'email' => $recipient->toString(), |
| 127 | + $recipientPayload = [ |
| 128 | + 'email' => $recipient->getAddress(), |
124 | 129 | 'type' => $type, |
125 | 130 | ]; |
| 131 | + |
| 132 | + if ($recipient instanceof NamedAddress) { |
| 133 | + $recipientPayload['name'] = $recipient->getName(); |
| 134 | + } |
| 135 | + |
| 136 | + $recipients[] = $recipientPayload; |
126 | 137 | } |
127 | 138 |
|
128 | 139 | return $recipients; |
|
0 commit comments