doulai7239 2016-02-09 09:27
浏览 18
已采纳

将电子邮件收件人添加到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.

  • 写回答

1条回答 默认 最新

  • douhuan6157 2016-02-09 18:01
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大