We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    If, you want to send another contact mail copy to another email address as a BCC? Then follow the below steps.

    Step 1: Create a registration file like Magemonkeys/ContactCc/registration.php

    <?php
    MagentoFrameworkComponentComponentRegistrar::register(
        MagentoFrameworkComponentComponentRegistrar::MODULE,
        'Magemonkey_ContactCc',
        __DIR__
    );

    Step 2: Create di file like Magemonkeys/ContactCc/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">
        <preference for="MagentoContactControllerIndexPost" type="MagemonkeyContactCcRewriteMagentoContactControllerIndexPost"/>
    </config>

    Step 3: Create module file like Magemonkeys/ContactCc/etc/module.xml

    <?xml version="1.0" ?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
        <module name="Magemonkey_ContactCc" setup_version="1.0.2"/>
    </config>

    Step 4: Create a system file like Magemonkeys/ContactCc/etc/adminhtml/system.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
        <system>
            <section id="contact" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
                <tab>general</tab>
                <group id="email" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Email Options</label>
                    <field id="copy_to" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
                        <label>Send Contact Us Email Copy To</label>
                        <comment>Comma-separated</comment>
                    </field>                
                </group>
            </section>
        </system>
    </config>

    Step 5: Create helper file like Magemonkeys/ContactCc/Helper/Email.php

    <?php
    
    namespace MagemonkeyContactCcHelper;
    
    use MagentoFrameworkAppHelperAbstractHelper;
    use MagentoFrameworkAppHelperContext;
    use MagentoStoreModelStoreManagerInterface;
    use MagentoFrameworkAppConfigScopeConfigInterface;
    
    /**
     * Class Email
     * @package MagemonkeyContactCcHelper
     */
    class Email extends AbstractHelper
    {
        const XML_PATH_EMAIL_COPY_METHOD = 'contact/email/copy_method';
        const XML_PATH_EMAIL_COPY_TO = 'contact/email/copy_to';
    
        /**
         * @var StoreManagerInterface
         */
        private $storeManager;
    
        /**
         * @var ScopeConfigInterface
         */
        protected $scopeConfig;
    
        /**
         * Email constructor.
         * @param Context $context
         * @param StoreManagerInterface $storeManager
         * @param ScopeConfigInterface $scopeConfig
         */
        public function __construct(
            Context $context,
            StoreManagerInterface $storeManager,
            ScopeConfigInterface $scopeConfig
        ) {
            $this->storeManager = $storeManager;
            $this->scopeConfig = $scopeConfig;
            parent::__construct($context);
        }
    
        /**
         * @return array|bool
         * @throws MagentoFrameworkExceptionNoSuchEntityException
         */
        public function getEmailCopyTo()
        {
            $data = $this->getConfigValue(self::XML_PATH_EMAIL_COPY_TO, $this->storeManager->getStore()->getId());
            if (!empty($data)) {
                return explode(',', $data);
            }
            return false;
        }
    
        /**
         * @return mixed
         * @throws MagentoFrameworkExceptionNoSuchEntityException
         */
        public function getCopyMethod()
        {
            return $this->getConfigValue(self::XML_PATH_EMAIL_COPY_METHOD, $this->storeManager->getStore()->getId());
        }
    
        /**
         * @param $xmlPath
         * @param null $storeId
         * @return mixed
         */
        public function getConfigValue($xmlPath, $storeId = null)
        {
            return $this->scopeConfig->getValue(
                $xmlPath,
                MagentoStoreModelScopeInterface::SCOPE_STORE,
                $storeId
            );
        }
    }

    Step 6: Create PHP file like Magemonkey/ContactCc/Rewrite/Magento/Contact/Controller/Index/Post.php

    <?php
    
    namespace MagemonkeyContactCcRewriteMagentoContactControllerIndex;
    
    use MagentoFrameworkAppArea;
    use MagentoContactModelConfigInterface;
    use MagentoFrameworkAppActionContext;
    use MagentoFrameworkDataObject;
    use MagentoFrameworkAppRequestDataPersistorInterface;
    use MagemonkeyContactCcHelperEmail;
    use PsrLogLoggerInterface;
    use MagentoFrameworkExceptionLocalizedException;
    use MagentoContactModelMailInterface;
    use MagentoFrameworkAppObjectManager;
    use MagentoFrameworkTranslateInlineStateInterface;
    use MagentoStoreModelStoreManagerInterface;
    use MagentoFrameworkMailTemplateTransportBuilder;
    
    /**
     * Class Post
     * @package MagemonkeyContactCcRewriteMagentoContactControllerIndex
     */
    class Post extends MagentoContactControllerIndexPost
    {
        /**
         * @var Context
         */
        private $context;
    
        /**
         * @var ConfigInterface
         */
        private $contactsConfig;
    
        /**
         * @var MailInterface
         */
        private $mail;
    
        /**
         * @var DataPersistorInterface
         */
        private $dataPersistor;
    
        /**
         * @var LoggerInterface
         */
        private $logger;
    
        /**
         * @var Email
         */
        private $helper;
    
        /**
         * @var StateInterface
         */
        private $inlineTranslation;
    
        /**
         * @var TransportBuilder
         */
        private $transportBuilder;
    
        /**
         * @var StoreManagerInterface
         */
        private $storeManager;
    
        /**
         * Post constructor.
         * @param Context $context
         * @param ConfigInterface $contactsConfig
         * @param MailInterface $mail
         * @param DataPersistorInterface $dataPersistor
         * @param Email $helper
         * @param LoggerInterface|null $logger
         * @param TransportBuilder $transportBuilder
         * @param StateInterface $inlineTranslation
         * @param StoreManagerInterface|null $storeManager
         */
        public function __construct(
            Context $context,
            ConfigInterface $contactsConfig,
            MailInterface $mail,
            DataPersistorInterface $dataPersistor,
            Email $helper,
            LoggerInterface $logger = null,
            TransportBuilder $transportBuilder,
            StateInterface $inlineTranslation,
            StoreManagerInterface $storeManager = null
        ) {
            $this->context = $context;
            $this->contactsConfig = $contactsConfig;
            $this->mail = $mail;
            $this->dataPersistor = $dataPersistor;
            $this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
            $this->helper = $helper;
            $this->transportBuilder = $transportBuilder;
            $this->inlineTranslation = $inlineTranslation;
            $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
            parent::__construct($context, $contactsConfig, $mail, $dataPersistor, $logger);
        }
    
        /**
         * Contact store
         * @return MagentoFrameworkControllerResultRedirect
         */
        public function execute()
        {
            if (!$this->getRequest()->isPost()) {
                return $this->resultRedirectFactory->create()->setPath('*/*/');
            }
            try {
                $this->sendEmail($this->validatedParams());
                $this->messageManager->addSuccessMessage(
                    __('Thanks for contacting us with your comments and questions. We'll respond to you very soon.')
                );
                $this->dataPersistor->clear('contact_us');
            } catch (LocalizedException $e) {
                $this->messageManager->addErrorMessage($e->getMessage());
                $this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
            } catch (Exception $e) {
                $this->logger->critical($e);
                $this->messageManager->addErrorMessage(
                    __('An error occurred while processing your form. Please try again later.')
                );
                $this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
            }
            return $this->resultRedirectFactory->create()->setPath('contact/index');
        }
    
        /**
         * Send email
         * @param array $post
         * @throws MagentoFrameworkExceptionMailException
         * @throws MagentoFrameworkExceptionNoSuchEntityException
         */
        public function sendEmail($post)
        {
            $this->send(
                $post['email'],
                ['data' => new DataObject($post)]
            );
        }
    
        /**
         * Send email
         * @param $replyTo
         * @param array $variables
         * @throws MagentoFrameworkExceptionMailException
         * @throws MagentoFrameworkExceptionNoSuchEntityException
         */
        public function send($replyTo, array $variables)
        {
            $replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
    
            $this->inlineTranslation->suspend();
    
            try {
                $this->configureEmailTemplate($replyTo, $replyToName, $variables);
                $this->transportBuilder->addTo($this->contactsConfig->emailRecipient());
    
                $copyTo = $this->helper->getEmailCopyTo();
                if (!empty($copyTo) && $this->helper->getCopyMethod() == 'bcc') {
                    foreach ($copyTo as $email) {
                        $this->transportBuilder->addBcc($email);
                    }
                }
    
                $transport = $this->transportBuilder->getTransport();
                $transport->sendMessage();
    
                $this->sendCopyTo($replyTo, $replyToName, $variables);
            } catch (Exception $e) {
                $this->logger->error($e->getMessage());
            } finally {
                $this->inlineTranslation->resume();
            }
        }
    
        /**
         * Prepare and send copy email message
         * @param string $replyTo
         * @param string $replyToName
         * @param array $variables
         * @return void
         */
        public function sendCopyTo($replyTo, $replyToName, $variables)
        {
            $copyTo = $this->helper->getEmailCopyTo();
            if (!empty($copyTo) && $this->helper->getCopyMethod() == 'copy') {
                foreach ($copyTo as $email) {
                    $this->configureEmailTemplate($replyTo, $replyToName, $variables);
                    $this->transportBuilder->addTo($email);
                    $transport = $this->transportBuilder->getTransport();
                    $transport->sendMessage();
                }
            }
        }
    
        /**
         * Configure email template
         * @param string $replyTo
         * @param string $replyToName
         * @param array $variables
         * @return void
         */
        protected function configureEmailTemplate($replyTo, $replyToName, $variables)
        {
            $this->transportBuilder->setTemplateIdentifier($this->contactsConfig->emailTemplate());
            $this->transportBuilder->setTemplateOptions([
                'area' => Area::AREA_FRONTEND,
                'store' => $this->storeManager->getStore()->getId()
            ]);
            $this->transportBuilder->setTemplateVars($variables);
            $this->transportBuilder->setFrom($this->contactsConfig->emailSender());
            $this->transportBuilder->setReplyTo($replyTo, $replyToName);
        }
    
        /**
         * Validate form params
         * @return array
         * @throws Exception
         */
        private function validatedParams()
        {
            $request = $this->getRequest();
            if (trim($request->getParam('name')) === '') {
                throw new LocalizedException(__('Name is missing'));
            }
            if (trim($request->getParam('comment')) === '') {
                throw new LocalizedException(__('Comment is missing'));
            }
            if (false === strpos($request->getParam('email'), '@')) {
                throw new LocalizedException(__('Invalid email address'));
            }
            if (trim($request->getParam('hideit')) !== '') {
                throw new LocalizedException(__('Error'));
            }
            return $request->getParams();
        }
    }

    Step 7: Then after run the below commands.

    php bin/magento setup:upgrade
    php bin/magento setup:static-content:deploy
    php bin/magento cache:flush

    That’s it…

    Now clean cache and check in Admin > STORES > Settings > Configuration > GENERAL > Contacts. Your new email address field option appear here.

    field_5bfb909c5ccae

      Get a Free Quote