这是我的代码,当我将它发送给一个收件人时工作正常,即如果我使用'rec1@gmail.com'
(单个电子邮件)它工作正常。但是我想要包含第二个电子邮件ID rec2@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);
答案 0 :(得分: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()
);
答案 1 :(得分:-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
不要忘记保存并清除缓存..