How to add bcc or cc to magento

I don't know how to add cc or bcc in the following encodings. I tried bcc but the mail can't go. Please, help!..

Codes

$data = array('name' => $username, 'to_user_id' => $to_userid, 'email' => $email, 'telephone' => $telephone, 'title' => $title, 'ip' => $ip, 'message' => $message);

            $templateId =1;
            $sender = Array('name' => "Admin", 'email' => "webmaster@example.com");
            $useremail = $product_user;
            $emailName = $username;
            $vars = array('username' => $username, 'telephone' => $telephone, 'mail_id' => $email, 'title' => $title, 'message' => $message, 'object' => $this);
            $storeId = Mage::app()->getStore()->getId();
            $mailSubject = 'mail check';
            $translate = Mage::getSingleton('core/translate');
            $translate->setTranslateInline(false);
            Mage::getModel('core/email_template')
                ->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))
                ->setTemplateSubject($mailSubject)
                ->setBcc('zzz@gmail.com')
                ->sendTransactional($templateId, $sender, $useremail, $emailName, $vars, $storeId);
            $translate->setTranslateInline(true);

                $model = Mage::getModel("contacts/contacts")->setData($data)->save();


            Mage::getSingleton("core/session")->addSuccess("You have been successfully sent your mail..");
            $this->_redirectReferer();
            return;

      

+3


source to share


2 answers


You can use addBcc('zzz@gmail.com')

instead setBcc('zzz@gmail.com')

in your code or change your code like this



//mail transaction
$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


source


Mage_Core_Model_Email class

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

.

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

      



After that, your code could be:

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

      

+3


source







All Articles