This seems to be a Joomla (or maybe php) bug. I checked the coding against the sendMail() method for
JMail api and your code looked correct, but alawys returned an error.
After amending your code in mail.php as follows I managed to get both the cc list and email names working; it should also work for the WordPress code, because emails need to be listed either as address or as name<name@address> (which should work in header). But I have not tested WordPress.
Modified code for the Joomla version of
public function send()
// ADDED
$cc_recipients = (is_array($this->cc)) ? $this->cc : array($this->cc);
$bcc_recipients = (is_array($this->bcc)) ? $this->bcc : array($this->bcc);
$cc_recipient_names = array_map(function($address) {
$name = explode('<', $address);
return (isset($name[1])) ? trim($name[0]) : '';
}, $cc_recipients);
$cc_recipients = array_map(function($address, $name, $key) {
if ($name == '') return $address;
else return trim(explode('<', $address)[1], '> ');
}, $cc_recipients, $cc_recipient_names, array_keys($cc_recipients));
$bcc_recipient_names = array_map(function($address) {
$name = explode('<', $address);
return (isset($name[1])) ? trim($name[0]) : '';
}, $bcc_recipients);
$bcc_recipients = array_map(function($address, $name, $key) {
if ($name == '') return $address;
else return trim(explode('<', $address)[1], '> ');
}, $bcc_recipients, $bcc_recipient_names, array_keys($bcc_recipients));
// END ADDED
$mailer = \JFactory::getMailer();
$mailer->setSender([$this->from_email, $this->from_name]);
$mailer->addRecipient($this->to);
$mailer->setSubject($this->subject);
$mailer->setBody($this->body);
$mailer->isHtml(($this->mode == 'html') ? true : false); // AMENDED
$mailer->addCc($cc_recipients, $cc_recipient_names); // ADDED
$mailer->addCc($bcc_recipients, $bcc_recipient_names); // ADDED
foreach($this->attachments as $attachment){
$mailer->addAttachment($attachment);
}
$result = $mailer->Send(); // ADDED; FOLLOWING COMMENTED OUT
/*$result = $mailer->sendMail(
$this->from_email,
$this->from_name,
$this->to,
$this->subject,
$this->body,
($this->mode == 'html') ? true : false,
$this->cc,
$this->bcc,
!empty($this->attachments) ? $this->attachments : null,
$this->reply_email,
$this->reply_name
);*/