4

这是我的代码,当我将其发送给一个收件人时,它工作正常,即,如果我使用'rec1@gmail.com'(单个电子邮件)它工作正常。但是,我也想包含第二个电子邮件 IDrec2@gmail.com并编写如下代码:'rec1@gmail.com,rec2@gmail.com'但这不起作用。

让我知道如何实现此功能?

$templateId = 1;
$sender = array(
    'name' => 'swapnesh',
    'email' => 'sender@gmail.com'
);
$store = Mage::app()->getStore();
$vars = array(
    'my_var' => 15,
    'another_var' => 12
);
$translate = Mage::getSingleton('core/translate');

// Send your email
Mage::getModel('core/email_template')->sendTransactional(
    $templateId,
    $sender,
    'rec1@gmail.com,rec2@gmail.com',
    'Recipient Name',
    $vars,
    $store->getId()
);
$translate->setTranslateInline(true);
4

2 回答 2

8

答案在Mage_Core_Model_Email_Template::send()

您可以看到,$email并且$names参数可以是两个数组。所以在你的情况下,如果将是:

$recipients = [
    'rec1@gmail.com' => 'Recipient1 Name',
    'rec2@gmail.com' => 'Recipient2 Name'
];

Mage::getModel('core/email_template')->sendTransactional(
    $templateId,
    $sender,
    array_keys($recipients),
    array_values($recipients),
    $vars,
    $store->getId()
);
于 2012-10-04T10:53:02.673 回答
-2

要在联系我们 Magento 中向多个收件人发送电子邮件,您可以通过这种方式进行托盘发送。

第一步,你可以在 app/code/core/Mage/Contacts/Controllers/IndexController.php 找到这一行

$mailTemplate = Mage::getModel('core/email_template');
            /* @var $mailTemplate Mage_Core_Model_Email_Template */
            $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                ->setReplyTo($post['email'])
                ->sendTransactional(
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                    null,
                    array('data' => $postObject)
                );

并修改为:

                $recipients = Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT);
                if ($recipients)
                {
                        $recipients = explode(";",$recipients);
                        if(count($recipients))
                        {
            foreach($recipients as $recipient) {

            $mailTemplate = Mage::getModel('core/email_template');
            /* @var $mailTemplate Mage_Core_Model_Email_Template */
            $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                ->setReplyTo($post['email'])
                ->sendTransactional(
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                    $recipient,
                    null,
                    array('data' => $postObject)
                );

                if (!$mailTemplate->getSentSuccess()) {
                throw new Exception();
                }
         }
     }
}

并且不要忘记在 app/code/core/Mage/Contacts/etc/system.xml 上评论验证 javascript

找到这一行:

<recipient_email translate="label">
    <label>Send Emails To</label>
    <frontend_type>text</frontend_type>
<!--<validate>validate-email</validate>-->
    <sort_order>10</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</recipient_email>

对此行发表评论<validate>validate-email</validate>

此代码适用于 magento 1.7.0.2 中的我。我希望这对您的问题有所帮助.. :D

不要忘记保存和清除缓存..

于 2013-08-29T08:50:32.230 回答