Search code examples
phpmagentomagento-1.7magento-1.8magento-1.9.1

Magento addCc in transactional email


I am trying to send CC to another email using the previously-mentioned code,

and I am getting the following error:

Varien_Exception Object ( [message:protected] => Invalid method Mage_Core_Model_Email_Template::addCc(Array ( [0] => [email protected] ) ) [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] => [email protected] ) ) ) [1] => Array ( [file] => /var/domains/alldaychemist/adminuser.php [line] => 59 [function] => addCc [class] => Mage_Core_Model_Email_Template [type] => -> [args] => Array ( [0] => [email protected] ) ) ) [previous:Exception:private] => )

When ever I send the email using the below code I get this error,

-Invalid method Mage_Core_Model_Email_Template::addCc

My code looks like this:

$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' => '[email protected]',
    'customerEmail' => 'Mr. Nil Cust');

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

// Send Transactional Email
try{
Mage::getModel('core/email_template')
->addCc('[email protected]')
->addBcc('[email protected]')
->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
}
catch(Exception $e){
    print_r($e);
}   

$translate->setTranslateInline(true);

Solution

  • Unlike addBcc,addCc is not defined in class Mage_Core_Model_Email_Template. You can either extend Mage_Core_Model_Email_Template class to include addCc method in a similar fashion as addBcc, or modify your code like this:

    // Send Transactional Email
    try{
      $mail = Mage::getModel('core/email_template');
      $mail->getMail()->addCc('[email protected]');  
    
      $mail->addBcc('[email protected]')
      ->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
    }
    catch(Exception $e){
        print_r($e);
    }