@@ -638,7 +638,72 @@ private function _smtp_close() {
638638 return true ;
639639 }
640640
641+ private function _extract_names ($ data ) {
642+ $ senders = array ();
643+
644+ $ data = stripslashes (preg_replace ("'( \t| \r| \n)' " , '' , $ data ));
645+
646+ if (trim ($ data ) == '' ) return $ senders ;
647+
648+ $ armail = array ();
649+ $ counter = 0 ; $ inthechar = 0 ;
650+ $ chartosplit = ',; ' ; $ protectchar = '" ' ; $ temp = '' ;
651+ $ closed = 1 ;
652+
653+ for ($ i = 0 ; $ i < strlen ($ data ); $ i ++) {
654+ $ thischar = $ data [$ i ];
655+ if ($ thischar == '< ' && $ closed ) $ closed = 0 ;
656+ if ($ thischar == '> ' && !$ closed ) $ closed = 1 ;
657+ if ($ thischar == $ protectchar ) $ inthechar = ($ inthechar ) ? 0 : 1 ;
658+ if ((strpos ($ chartosplit , $ thischar ) !== false ) && !$ inthechar && $ closed ) {
659+ $ armail [] = $ temp ;
660+ $ temp = '' ;
661+ } else {
662+ $ temp .= $ thischar ;
663+ }
664+ }
665+
666+ if (trim ($ temp ) != '' ) {
667+ $ armail [] = trim ($ temp );
668+ unset($ temp );
669+ }
670+
671+ foreach ($ armail as $ thisPart ) {
672+ $ thisPart = trim (preg_replace ('/^"(.*)"$/i ' , '$1 ' , trim ($ thisPart )));
673+ if ($ thisPart != '' ) {
674+ $ email = '' ;
675+ $ name = '' ;
676+ if (preg_match ('/(.*)<(.*)>/i ' , $ thisPart , $ matches )) {
677+ $ email = trim ($ matches [2 ]);
678+ $ name = trim ($ matches [1 ]);
679+ } else {
680+ if (preg_match ('/([-a-z0-9_$+.]+@[-a-z0-9_.]+[-a-z0-9_]+)((.*))/i ' , $ thisPart , $ matches )) {
681+ $ email = $ matches [1 ];
682+ $ name = $ matches [2 ];
683+ } else {
684+ $ email = $ thisPart ;
685+ }
686+ }
641687
688+ $ email = preg_replace ('/<(.*) \\>/ ' , '$1 ' , $ email );
689+ $ name = preg_replace ('/"(.*)"/ ' , '$1 ' , trim ($ name ));
690+ $ name = preg_replace ('/\((.*)\)/ ' , '$1 ' , $ name );
691+
692+ if ($ name == '' ) $ name = $ email ;
693+ if ($ email == '' ) $ email = $ name ;
694+ $ senders [] = array (
695+ 'name ' => $ name ,
696+ 'mail ' => $ email
697+ );
698+ unset($ name );
699+ unset($ email );
700+ }
701+ }
702+ unset($ armail );
703+ unset($ thisPart );
704+
705+ return $ senders ;
706+ }
642707
643708 /**
644709 * Send the mail to one or more recipients
@@ -683,6 +748,7 @@ public function send($recipients) {
683748 $ result = $ this ->_smtp_login ();
684749 if (!$ result ) return false ;
685750 }
751+ $ bcc_cc_sent = false ;
686752 foreach ($ recipients as $ recipname => $ recip ) {
687753 if ($ this ->_sent_mails >= $ this ->smtp_max_mails ) {
688754 // close connection to smtp and reconnect
@@ -705,6 +771,19 @@ public function send($recipients) {
705771 fputs ($ this ->_smtp_conn , 'RCPT TO: < ' . $ recip . '> ' . $ this ->_crlf );
706772 $ response = fgets ($ this ->_smtp_conn , 515 );
707773
774+ if ($ bcc_cc_sent == false ) {
775+ $ add_recips = array ();
776+ if ($ this ->getHeader ('Cc ' ) != '' ) $ add_recips = array_merge ($ add_recips , $ this ->_extract_names ($ this ->getHeader ('Cc ' )));
777+ if ($ this ->getHeader ('Bcc ' ) != '' ) $ add_recips = array_merge ($ add_recips , $ this ->_extract_names ($ this ->getHeader ('Bcc ' )));
778+ foreach ($ add_recips as $ add_recip ) {
779+ if (!$ add_recip ['mail ' ]) continue ;
780+ fputs ($ this ->_smtp_conn , 'RCPT TO: < ' . $ this ->_encodeHeader ($ add_recip ['mail ' ], $ this ->mail_charset ) . '> ' . $ this ->_crlf );
781+ $ response = fgets ($ this ->_smtp_conn , 515 );
782+ }
783+ unset($ add_recips );
784+ $ bcc_cc_sent = true ;
785+ }
786+
708787 //The Email
709788 fputs ($ this ->_smtp_conn , 'DATA ' . $ this ->_crlf );
710789 $ response = fgets ($ this ->_smtp_conn , 515 );
0 commit comments