@@ -135,6 +135,7 @@ public function buildMessage(array $params, array $vars = []): Message
135
135
// Create message object.
136
136
$ message = new Message ();
137
137
$ headers = $ message ->getEmail ()->getHeaders ();
138
+ $ email = $ message ->getEmail ();
138
139
139
140
// Extend parameters with defaults.
140
141
$ params += [
@@ -201,9 +202,9 @@ public function buildMessage(array $params, array $vars = []): Message
201
202
case 'cc ' :
202
203
case 'bcc ' :
203
204
case 'reply_to ' :
204
- $ recipients = $ this ->processRecipients ($ key , $ params );
205
- foreach ( $ recipients as $ address ) {
206
- $ message ->$ key ($ address );
205
+ if ( $ recipients = $ this ->processRecipients ($ key , $ params )) {
206
+ $ key = $ key === ' reply_to ' ? ' replyTo ' : $ key ;
207
+ $ email ->$ key (... $ recipients );
207
208
}
208
209
break ;
209
210
case 'tags ' :
@@ -241,9 +242,13 @@ protected function processRecipients(string $type, array $params): array
241
242
if (is_array ($ recipients ) && Utils::isAssoc ($ recipients )) {
242
243
$ list [] = $ this ->createAddress ($ recipients );
243
244
} else {
244
- if (is_array ($ recipients [0 ])) {
245
- foreach ($ recipients as $ recipient ) {
246
- $ list [] = $ this ->createAddress ($ recipient );
245
+ if (is_array ($ recipients )) {
246
+ if (count ($ recipients ) ===2 && $ this ->isValidEmail ($ recipients [0 ]) && is_string ($ recipients [1 ])) {
247
+ $ list [] = $ this ->createAddress ($ recipients );
248
+ } else {
249
+ foreach ($ recipients as $ recipient ) {
250
+ $ list [] = $ this ->createAddress ($ recipient );
251
+ }
247
252
}
248
253
} else {
249
254
if (is_string ($ recipients ) && Utils::contains ($ recipients , ', ' )) {
@@ -450,6 +455,11 @@ protected function jsonifyRecipients(array $recipients): string
450
455
return json_encode ($ json );
451
456
}
452
457
458
+ protected function isValidEmail ($ email ): bool
459
+ {
460
+ return is_string ($ email ) && filter_var ($ email , FILTER_VALIDATE_EMAIL ) !== false ;
461
+ }
462
+
453
463
/**
454
464
* @return void
455
465
* @deprecated 4.0 Switched from Swiftmailer to Symfony/Mailer - No longer supported
0 commit comments