Magento addCc在交易电子邮件中

时间:2014-09-12 02:42:56

标签: php magento magento-1.7 magento-1.8 magento-1.9.1

我正在尝试send CC to another email使用前面提到的代码

我收到以下错误:

Varien_Exception Object ( [message:protected] => Invalid method Mage_Core_Model_Email_Template::addCc(Array ( [0] => abc@gmail.com ) ) [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/domains/alldaychemist/lib/Varien/Object.php [line:protected] => 652 [trace:Exception:private] => Array ( [0] => Array ( [file] => /var/domains/alldaychemist/adminuser.php [line] => 59 [function] => __call [class] => Varien_Object [type] => -> [args] => Array ( [0] => addCc [1] => Array ( [0] => abc@gmail.com ) ) ) [1] => Array ( [file] => /var/domains/alldaychemist/adminuser.php [line] => 59 [function] => addCc [class] => Mage_Core_Model_Email_Template [type] => -> [args] => Array ( [0] => abc@gmail.com ) ) ) [previous:Exception:private] => )

当我使用以下代码发送电子邮件时,我收到此错误,

-Invalid method Mage_Core_Model_Email_Template::addCc

我的代码如下所示:

$templateId = 15;

// Set sender information
$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
$sender = array('name' => $senderName,
    'email' => $senderEmail);

// Set recepient information
$recepientEmail = 'adcc@gmailcom';
$recepientName = 'John Doe';        

// Get Store ID
$store = Mage::app()->getStore()->getId();

// Set variables that can be used in email template
$vars = array('customerName' => 'customer@example.com',
    'customerEmail' => 'Mr. Nil Cust');

$translate  = Mage::getSingleton('core/translate');

// Send Transactional Email
try{
Mage::getModel('core/email_template')
->addCc('abc@gmail.com')
->addBcc('abcd2@gmail.com')
->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
}
catch(Exception $e){
    print_r($e);
}   

$translate->setTranslateInline(true);

1 个答案:

答案 0 :(得分:3)

addBcc不同,addCc未在班级Mage_Core_Model_Email_Template中定义。您可以以与Mage_Core_Model_Email_Template类似的方式扩展addCc类以包含addBcc方法,也可以像这样修改代码:

// Send Transactional Email
try{
  $mail = Mage::getModel('core/email_template');
  $mail->getMail()->addCc('abc@gmail.com');  

  $mail->addBcc('abcd2@gmail.com')
  ->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
}
catch(Exception $e){
    print_r($e);
}