2

I have created a transactional email template and sending mail using below code :

$to_user_email = 'test@gmail.com';
$to_user = 'test';

$emailTemplate = Mage::getModel('core/email_template')->loadByCode('My Template');
$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');     
$sender = array('name' => $senderName,
            'email' => $senderEmail);
$store = Mage::app()->getStore()->getId();

// Set variables that can be used in email template
$vars = array();
$vars['order_id'] = 'order_id';
$vars['content'] = 'content';

$processedTemplate = $emailTemplate->getProcessedTemplate($vars);

$mail = Mage::getModel('core/email')
     ->setToName($to_user)
     ->setToEmail($to_user_email)
     ->setBody($processedTemplate)
     ->setSubject('Subject')
     ->setFromEmail($senderEmail)
     ->setFromName($senderName)
     ->setType('TEXT')
     ->setCc(array('test1@gmail.com','test2@gmail.com'));
$mail->send();

From above code email sent to $to_user_email but cc not sent to 'test1@gmail.com', 'test2@gmail.com'.

How to send cc or bcc to multiple email address?

1
  • How to configure mail in magento
    – Gem
    Jul 22, 2016 at 5:12

2 Answers 2

8

Use below code:

$mail = Mage::getModel('core/email_template');
$mail->getMail()->addCc('zzz@gmail.com');
$mail->addBcc('zzz@gmail.com')
    ->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))
    ->setTemplateSubject($mailSubject)
    ->sendTransactional($templateId, $sender, $useremail, $emailName, $vars, $storeId);
4
  • Hello @Prashant Valanda, where you set My Template transactional email template? Jul 22, 2016 at 5:01
  • Instead of $templateId you need to pass your template Jul 22, 2016 at 5:04
  • I have tried this code but no email sent to $useremail and also not sent to cc/bcc email address. Jul 22, 2016 at 5:24
  • nice to hear it is working for you.If it helps you mark as accepted for further use. Jul 22, 2016 at 5:43
2

Please check below code

                $storeId=Mage::app()->getStore()->getId();
                $emailTemplateId='Youe email temlate';
                //Multiple BCC email address
                $add_bcc=array("someone@domain.com","someone2@domain.com");
                //Multiple CC email address
                $add_cc=array("someone3@domain.com","someone4@domain.com");
                $email='useremail@domain.com';
                $sender = Array('name' => 'test','email' => 'test@domain.com');
                $mailSubject='Your subject';
                $vars = Array('name' => 'Your message');

                $translate=Mage::getModel('core/email_template');
                $translate->getMail()->addCc($add_cc);
                $translate->setTemplateSubject($mailSubject)
                    ->addBCC($add_bcc)
                    ->sendTransactional($emailTemplateId, $sender, $email, null, $vars, $storeId);
                $translate->setTranslateInline(true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.