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

时间:2016-02-09 09:27:36

标签: php email joomla3.0

无法在邮件服务器上为Joomla本身发送的授权邮件设置CC或转发,但我们希望存储这些电子邮件。 问题是:如何在特定插件的php中设置它? (插件正在发送这些电子邮件) 代码:

        // 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', '');

当我替换最后一行时: $ recipient =('my@email.com'),然后我收到了该消息,但我想要一个访问者和复制对我来说。 感谢您的建议

好的,实际上这段代码启动了该邮件的发送:

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

当我复制该代码时,将其粘贴到下面,并将 $ recipient 替换为我的电子邮件,它可以正常工作:我在两个地址上都传递了相同的消息。但是我需要它像CC(抄送)一样,并且在邮件标题中有原始的收件人地址,然后发送给我。

1 个答案:

答案 0 :(得分:1)

使用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();

这应该使用PHP向任何人发送HTML电子邮件,并通过直接发送,CC或BCC复制电子邮件中的其他用户,具体取决于您使用的方法。