Search code examples
yii2swiftmailer

Yii2: How to set bc and bcc in Switfmailer?


Three short questions:

  1. How to set swiftmailer sending carbon copy or/and a blind carbon copy of mail?
  2. Where could I get information about this? I have read articles about Swiftmailer but didn't find anything about bc and bcc
  3. Is my intention supported by swiftmailer, at all?

Solution

    1. You need to use ->setBcc($email) and ->setCc($email) repectively.

    2. Refer to the MessageInterface class to see the available methods,

      See a method below from my ContactForm Model which sends an email with bcc cc and to

          /**
          * @param $email
          */
          private function sendEmail($email)
          {
              return Yii::$app->mailer->compose()
                  ->setTo($email)
                  ->setBcc($email)
                  ->setCc($email)
                  ->setFrom([$email => 'Omer Aslam'])
                  ->setSubject('some subject')
                  ->setTextBody('test text body email')
                  ->send();
          }
      
      
    3. Yes it is possible

    Hope it helps