0

Referring to this thread: https://stackoverflow.com/questions/30679036/how-to-add-bcc-or-cc-in-magento/51149678?noredirect=1#comment89282991_51149678

Kindly note I test it on my Magento Comunity Magento ver. 1.9.0.1 but didn't work and it's really important to me to have Copy and Blind Copy once the end user hit the submit button in my website contact form: https://www.khouryhome.com/contacts

0

Add the below code to your controller's postAction(Override the controller before do any modification for best practice):

$mailTemplate->getMail()->addCc('abc@example.com');
$mailTemplate->addBcc('xyz@example.com');

Just after the below line:

$mailTemplate = Mage::getModel('core/email_template');

Use below code for postAction:

public function postAction()
{
    $post = $this->getRequest()->getPost();
    if ( $post ) {
        $translate = Mage::getSingleton('core/translate');
        /* @var $translate Mage_Core_Model_Translate */
        $translate->setTranslateInline(false);
        try {
            $postObject = new Varien_Object();
            $postObject->setData($post);

            $error = false;

            if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
                $error = true;
            }

            if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
                $error = true;
            }

            if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
                $error = true;
            }

            if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
                $error = true;
            }

            if ($error) {
                throw new Exception();
            }

            $mailTemplate = Mage::getModel('core/email_template');
            //Added for CC
            $mailTemplate->getMail()->addCc('abc@example.com');
            //Added for BCC
            $mailTemplate->addBcc('xyz@example.com');

            /* @var $mailTemplate Mage_Core_Model_Email_Template */
            $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                ->setReplyTo($post['email'])
                ->sendTransactional(
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
                    Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
                    null,
                    array('data' => $postObject)
                );

            if (!$mailTemplate->getSentSuccess()) {
                throw new Exception();
            }

            $translate->setTranslateInline(true);

            Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
            $this->_redirect('*/*/');

            return;
        } catch (Exception $e) {
            $translate->setTranslateInline(true);

            Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
            $this->_redirect('*/*/');
            return;
        }

    } else {
        $this->_redirect('*/*/');
    }
}
  • you mean to add it here : public_html/app/code/core/Mage/Contacts/controllers right? – Marcos Jul 3 '18 at 13:20
  • You can add the code there in indexcontroller.php postAction and test if it's working fine then override it and add your code. – Sukumar Gorai Jul 3 '18 at 13:22
  • $mailTemplate = Mage::getModel('core/email_template'); $mailTemplate->setDesignConfig(array('area' => 'frontend')) ->setReplyTo($post['email']) ->sendTransactional( Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),array('info@khouryhome.com.lb','eazzam@khouryhome.com.lb', 'callcenter@khouryhome.com '),null,array('data' => $postObject) ); – Marcos Jul 3 '18 at 13:25
  • above is my code in postaction but still sending to one email account set in :"Send Emails To" i cleared my cache and browsing history as well as MAGENTO Cache but still one email receiver!! :( – Marcos Jul 3 '18 at 13:26
  • I have added the whole code for postAction. Please update it and check. – Sukumar Gorai Jul 3 '18 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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