7

I created a new email template, and that works fine in Magento, but I don't know how to add BCC addresses to the email.

PaulG
  • 13,871
  • 9
  • 56
  • 78
Maheswari
  • 131
  • 1
  • 2
  • 8

5 Answers5

13

You can add a bcc in the code where you send the email:

Mage::getModel('core/email_template')
     ->addBcc('em@ail.com')
     ->sendTransactional(...
Péter Gulyás
  • 1,111
  • 7
  • 8
6

This is the answer I've found:

 $mailTemplate->setTemplateSubject($mailSubject)->addBcc('youremail@mail.com')
->s‌​endTransactional($templateId, $sender, $email, $cus_name, $data, $storeId);
Stefan
  • 8,456
  • 3
  • 29
  • 38
Maheswari
  • 131
  • 1
  • 2
  • 8
3

You can do it in the config. Go to Sales > Sales E-Mails. Foreach transactional E-Mail you can enter Send Order Email Copy To and set the Method to BCC via Send Order Email Copy Method.

Sebastian Schmidt
  • 1,078
  • 7
  • 17
  • Thankyou for your reply..But i need to send email copy only for my custom email template. – Maheswari Feb 01 '13 at 08:47
  • I got the solution $mailTemplate->setTemplateSubject($mailSubject)->addBCC('youremail@mail.com')->sendTransactional($templateId, $sender, $email, $cus_name, $data, $storeId); – Maheswari Feb 01 '13 at 10:13
  • It seems i posted the answer at the same time you found the solution yourself. The main thing is that you have the solution finally. – Péter Gulyás Feb 06 '13 at 17:35
1

single email or array email is acceptable, check this :

app\code\core\Mage\Core\Model\Email\Template.php

Mage_Core_Model_Email_Template

public function addBcc($bcc)
{
    if (is_array($bcc)) {
        foreach ($bcc as $email) {
            $this->getMail()->addBcc($email);
        }
    }
    elseif ($bcc) {
        $this->getMail()->addBcc($bcc);
    }
    return $this;
}
Ansyori
  • 2,807
  • 3
  • 29
  • 37
0

Create di.xml: app/code/Py/Custom/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="\Magento\Framework\Mail\Template\TransportBuilder">
        <plugin name="TransportBuilderPlugin" type="Py\Custom\Plugin\Mail\Template\TransportBuilder" sortOrder="1" />
    </type>
</config>

Create Plugin: app/code/Py/Custom/Plugin/Mail/Template/TransportBuilder.php

<?php

namespace Py\Custom\Plugin\Mail\Template;

class TransportBuilder
{
    public function afterGetTransport(\Magento\Framework\Mail\Template\TransportBuilder $subject, $result)
    {
        $result->getMessage()->addCc('test@gmail.com');     
        return $result;
    }
}

Vishal
  • 1
  • 2