将电子邮件收件人添加到php脚本中

CC or forward is not possible to set on mailserver for authorisation mail sent by Joomla itself, but we'd like to store these e-mails. Question is: how to set it in php of specific plugin? (plugin is sending these e-mails) code:

        // send auth email to user who signed ...
    if ($signature_verification = (int)$this->settings->get('security.signature_verification', 0)) {
        // unpublished, visitor must verify it first
        $this->db->set('published', 0);

        $config = JFactory::getConfig();
        $from = $config->get('mailfrom', '');
        $fromname = $config->get('fromname', '');

        $recipient = (string)$this->db->get('email', '');

When I replace last line wth: $recipient = ('my@email.com'), then I get that message, but i want one for visitor and copy for me. Thanks for advice


OK, actually this piece of code initiates sending of that mail:

                if (
                $this->sendMail(
                    $from,
                    $fromname,
                    $recipient,
                    $subject,
                    $body
                ) !== true
            ) {
                throw new phpmailerException(JText::_('PLG_CONTENT_CDPETITIONS_EMAIL_SEND_FAILED'), 500);
            }

When I make copy of that code, paste it below, and replace $recipient with my e-mail, it works: I have the same message delivered on both adresses. But I need it have it like CC (carbon copy) and have original recipient adress in header of mail, which is delivered to me.

Use the built in mailer methods for Joomla:

$msg = "This is my email message.";
$subject = "Database Update Email";
$to = (string)$this->db->get('email');
$config = JFactory::getConfig();
$fromemail = $config->get('mailfrom');
$fromname = $config->get('fromname');
$from = array($fromemail,$fromname);

$mailer = JFactory::getMailer();
$mailer->setSender($from);
$mailer->addRecipient($to);
$mailer->addRecipient('you1@yourdomain.com');
$mailer->addRecipient('you2@yourdomain.com');
$mailer->addCC('you3@yourdomain.com');
$mailer->addBCC('you4@yourdomain.com');
$mailer->setSubject($subject);
$mailer->setBody($msg);
$mailer->isHTML();
$mailer->send();

This should use PHP to send an HTML email to whomever you want and copy other users on the email through either direct send, CC, or BCC depending on which method you use.