373 | | // Add any CC and BCC recipients |
374 | | if ( !empty( $cc ) ) { |
375 | | foreach ( (array) $cc as $recipient ) { |
376 | | try { |
377 | | // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>" |
378 | | $recipient_name = ''; |
379 | | if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { |
380 | | if ( count( $matches ) == 3 ) { |
381 | | $recipient_name = $matches[1]; |
382 | | $recipient = $matches[2]; |
383 | | } |
| 375 | // Add any CC, BCC, and Reply-To recipients |
| 376 | $recipient_headers = array( |
| 377 | // map the header names to the corresponding PHPMailer method for adding them to the message |
| 378 | 'cc' => 'AddCc', |
| 379 | 'bcc' => 'AddBcc', |
| 380 | 'reply_to' => 'AddReplyTo' |
| 381 | ); |
| 382 | |
| 383 | foreach ( $recipient_headers as $recipient_header => $add_method ) { |
| 384 | if ( ! empty( $$recipient_header ) ) { |
| 385 | foreach ( $$recipient_header as $recipient ) { |
| 386 | try { |
| 387 | // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>" |
| 388 | $recipient_name = ''; |
| 389 | if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { |
| 390 | if ( count( $matches ) == 3 ) { |
| 391 | $recipient_name = $matches[1]; |
| 392 | $recipient = $matches[2]; |
| 393 | } |
| 394 | } |
| 395 | call_user_func( array( $phpmailer, $add_method ), $recipient, $recipient_name ); |
| 396 | } catch ( phpmailerException $e ) { |
| 397 | continue; |
392 | | if ( !empty( $bcc ) ) { |
393 | | foreach ( (array) $bcc as $recipient) { |
394 | | try { |
395 | | // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>" |
396 | | $recipient_name = ''; |
397 | | if( preg_match( '/(.*)<(.+)>/', $recipient, $matches ) ) { |
398 | | if ( count( $matches ) == 3 ) { |
399 | | $recipient_name = $matches[1]; |
400 | | $recipient = $matches[2]; |
401 | | } |
402 | | } |
403 | | $phpmailer->AddBcc( $recipient, $recipient_name ); |
404 | | } catch ( phpmailerException $e ) { |
405 | | continue; |
406 | | } |
407 | | } |
408 | | } |
409 | | |