Index: branches/5.2.x/core/kernel/utility/email.php =================================================================== diff -u -N -r16031 -r16199 --- branches/5.2.x/core/kernel/utility/email.php (.../email.php) (revision 16031) +++ branches/5.2.x/core/kernel/utility/email.php (.../email.php) (revision 16199) @@ -1,6 +1,6 @@ _collectRecipients(); - $header_mapping = Array ( - EmailTemplate::RECIPIENT_TYPE_TO => 'To', - EmailTemplate::RECIPIENT_TYPE_CC => 'Cc', - EmailTemplate::RECIPIENT_TYPE_BCC => 'Bcc', - ); + $header_mapping = $this->getHeaderMapping(); $default_email = $this->Application->ConfigValue('DefaultEmailSender'); $this->recipients = array_map(Array ($this, '_transformRecipientsIntoPairs'), $this->recipients); @@ -452,6 +448,7 @@ $this->_overwriteToRecipient(); $this->_addRecipientByUserId(); $this->_addRecipientFromParams(); + $this->_moveDirectRecipients(); if ( ($this->emailTemplate->GetDBField('Type') == EmailTemplate::TEMPLATE_TYPE_ADMIN) && !$this->recipients[EmailTemplate::RECIPIENT_TYPE_TO] ) { // admin email template without direct recipient -> send to admin @@ -574,6 +571,47 @@ } /** + * Move recipients, that were added manually via "$this->sender->Add*" methods. + * + * @return void + * @access protected + */ + protected function _moveDirectRecipients() + { + foreach ( $this->getHeaderMapping() as $recipient_type => $header_name ) { + $manual_recipients = $this->sender->GetRecipientsByHeader($header_name); + + if ( !$manual_recipients ) { + continue; + } + + foreach ( $manual_recipients as $manual_recipient ) { + $this->recipients[$recipient_type][] = array( + 'RecipientName' => $manual_recipient['Name'], + 'RecipientAddressType' => EmailTemplate::ADDRESS_TYPE_EMAIL, + 'RecipientAddress' => $manual_recipient['Email'], + ); + } + + $this->sender->SetHeader($header_name, ''); + } + } + + /** + * Returns mapping between recipient type and header name. + * + * @return array + */ + protected function getHeaderMapping() + { + return array( + EmailTemplate::RECIPIENT_TYPE_TO => 'To', + EmailTemplate::RECIPIENT_TYPE_CC => 'Cc', + EmailTemplate::RECIPIENT_TYPE_BCC => 'Bcc', + ); + } + + /** * This is default recipient, when we can't determine actual one * * @return void