我正在尝试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);
答案 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);
}