Maniprakash Chinnasamy
Maniprakash Chinnasamy

Reputation: 2776

Add Bcc In Magento Email Model

i would like to add the bcc using below magento model.

i have tried to add addBcc('') with below model.

But does not work.

$mail = Mage::getModel('core/email')
                    ->setToName($senderName)
                    ->setToEmail($customerEmail)                    
                    ->setBody($processedTemplate)
                    ->setSubject('Subject')
                    ->setFromEmail($senderEmail)
                    ->setFromName($senderName)
                    ->setType('html')
                    ->send();

Any Help Much Appreciation! Thanks

Upvotes: 2

Views: 6484

Answers (2)

502_Geek
502_Geek

Reputation: 2126

Try this option. Please note that! If your using AWS, Bcc option didn't work. This is AWS potion and read their policy. Hope help

$mail = Mage::getModel('core/email_template')
                ->setToName($senderName)
                ->setToEmail($customerEmail)
                ->addBcc('[email protected]')                    
                ->setBody($processedTemplate)
                ->setTemplateSubject('Subject')
                ->setFromEmail($senderEmail)
                ->setFromName($senderName)
                ->setType('html')
                ->send();

You can also used like this snippets

 $emailTemplate = Mage::getModel('core/email_template');
 $emailTemplate->loadDefault('custom_email');
 $emailTemplate->setTemplateSubject('My Subject');
 $emailTemplate->setSenderName('Store Name');
 $emailTemplate->setSenderEmail('[email protected]');
 $emailTemplate->addBcc('[email protected]'); 
 $emailTemplateVariables['price'] = $currencySymbol.number_format($_product->getFinalPrice(), 2);
 $emailTemplateVariables['productname'] = $_product->getName();
 $emailTemplate->send($email, 'My Store', $emailTemplateVariables);`

Upvotes: 3

Marius
Marius

Reputation: 15206

The Mage_Core_Model_Email class does not support bcc (or cc). You need to override the send method and add this code right before $mail->send();.

if ($this->getBcc()) {
    $mail->addBcc($this->getBcc());
}

After that your code can be:

$mail = Mage::getModel('core/email')
                ->setToName($senderName)
                ->setToEmail($customerEmail)                    
                ->setBody($processedTemplate)
                ->setSubject('Subject')
                ->setFromEmail($senderEmail)
                ->setFromName($senderName)
                ->setType('html')
                ->setBcc('[email protected]') //bcc line added
                ->send();

Upvotes: 6

Related Questions