1
votes

i use laravel Mail function to send html mail to multiple email i create array of emails the message sent sucsessfully to all users but in the top of email message show all email addresses users , how to fix this problem how to use use cc or bcc in array of emails ?

 $product = Product::find($request->product_id)->get()->first();
     $emailUsers = User::select('email')->pluck('email')->toArray();
     $emailSubscribers = NewsLetter::select('email')->pluck('email')->toArray();
     $emails =array_unique(array_merge($emailUsers,$emailSubscribers), SORT_REGULAR);
     $end_at = Carbon::parse($request->end_at, 'UTC')->format('d/m/Y');
       $data = array(
          'name' =>$request->name,
          'product_name' =>$product->name,
          'product_img' =>$product->poster,
          'discount' =>$request->discount,
          'price_with_discount' =>$request->price_with_discount,
          'price_without_discount' =>$product->price,
          'start_at' =>$request->start_at,
          'end_at' =>$end_at,
          'description' =>$request->description
       );
       Mail::send('front-office.mails.promotion-letters.mail-promo', $data, function ($message) use($request,$emails) {
            $message->from('[email protected]','test');
            $message->to($emails)->subject
              ('Nouvelles promotion  !!');
       });
1
Use a foreach loop to send to each user individually.ceejayoz

1 Answers

0
votes

Laravel does support the following type on construct that might help you (see https://laravel.com/docs/5.7/mail#sending-mail) ...

Mail::to($request->user())
    ->cc($moreUsers)
    ->bcc($evenMoreUsers)
    ->send(new OrderShipped($order));

And the bcc() part will hide the recipients emails.