How To Set BCC For Customer Welcome Email In Magento?

how to set bcc for customer welcome email in magento 2

TASK

Set BCC for the welcome emails that are sent to the new customers when they register new accounts.

SOLUTIONS

  • The 1st method:

In your custom module

– Rewrite model Mage_Customer_Model_Customer in config.xml

<config>
			<global>
				<models>
					...
					<customer>
						<rewrite>
							<customer>Vendor_Namespace_Model_Customer_Customer</customer>
						</rewrite>
					</customer>
					...
				</models>
			</global>
		</config>

– Create Customer.php in path Vendor/Namespace/Model/Customer/Customer and override function _sendEmailTemplate

class Vendor_Namespace_Model_Customer_Customer extends Mage_Customer_Model_Customer
		{
			...
				protected function _sendEmailTemplate($template, $sender, $templateParams = array(), $storeId = null, $customerEmail = null)
				{
					$customerEmail = ($customerEmail) ? $customerEmail : $this->getEmail();
					/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
					$mailer = Mage::getModel('core/email_template_mailer');
					$emailInfo = Mage::getModel('core/email_info');
					$emailInfo->addTo($customerEmail, $this->getName());
					$mailer->addEmailInfo($emailInfo);

					//add bbc
					$mailer->addBcc('[email protected]');
					
					// Set all required params and send emails
					$mailer->setSender(Mage::getStoreConfig($sender, $storeId));
					$mailer->setStoreId($storeId);
					$mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));
					$mailer->setTemplateParams($templateParams);
					$mailer->send();
					return $this;
				}
			...
		}
  • The 2nd method:

Add the following code

$storeId=Mage::app()->getStore()->getId();
	$emailTemplateId='Youe email temlate';
	//Multiple BCC email address
	$add_bcc=array("[email protected]","[email protected]");
	//Multiple CC email address
	$add_cc=array("[email protected]","[email protected]");
	$email='[email protected]';
	$sender = Array('name' => 'test','email' => '[email protected]');
	$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);

See More Our Magento “How To” Series:

How To Customize Magento 2 Email Templates

How To Config Sitemap in Magento 2?

How To Use Flat Catalog In Magento 2?

How To Config URL Rewrite in Magento 2?

How To Create New Cart Price Rule In Magento 2

How To Create New Catalog Price Rule In Magento 2

How To Set Up Automatic Product Redirects in Magento 2?

Leave a Reply

Your email address will not be published. Required fields are marked *