5

I am trying to send email to single user means it's working fine.How can i send to multiple user?

$transport = $this->transportBuilder
           ->setTemplateIdentifier('my_email_template')
           ->setTemplateOptions(
                [
                    'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
                    'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
                ]
            )
           ->setTemplateVars($vars)
           ->setFrom($sender)
           ->addTo($toEmail)
           ->getTransport();
        $transport->sendMessage();
        $this->inlineTranslation->resume();

1 Answer 1

13

You may try this below code.

if you want send to multiple email address you can use array format like

$emails = ['[email protected]', '[email protected]'];

$transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
            ->setTemplateOptions(['area' => Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId])
            ->setTemplateVars($templateParams)
            ->setFrom('[email protected]')
            ->addTo($emails)
            ->setReplyTo('[email protected]')
            ->addBcc('[email protected]')
            ->getTransport();
        $transport->sendMessage();
3
  • More than 5 mails means how can I add?Is that any array format available? Commented Jun 30, 2017 at 4:17
  • @JeevaChezhiyan - you can send through array format if more than one email. like $emails = ['[email protected]', '[email protected]'];
    – Jjo
    Commented Jun 30, 2017 at 4:26
  • @Jjo, where to put this $emails variable ? Commented Sep 12, 2017 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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