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.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题