4

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

11

You may try this below code.

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

$emails = ['email1@test.com', 'email2@test.com'];

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

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.