I use Laravel 5.3
My controller like this :
auth()->user()->notify(new ConfirmOrder($invoice));
My notification like this :
<?php
...
class ConfirmOrder extends Notification implements ShouldQueue, ShouldBroadcast
{
use Queueable;
private $data;
public function __construct($data)
{
$this->data = $data;
}
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
$mail_myshop = explode(',', config('app.mail_myshop'));
return (new ConfirmOrderMail($this->data, $notifiable))
->to($notifiable->routeNotificationFor('mail'))
->bcc($mail_myshop)
->subject('Thanks');
}
}
My mailable like this :
<?php
...
class ConfirmOrderMail extends Mailable
{
use Queueable, SerializesModels;
public $data;
public $user;
public function __construct($data, $user)
{
$this->data = $data;
$this->user = $user;
}
public function build()
{
return $this->view('vendor.notifications.mail.email-confirm-order',['data'=>$this->data, 'name' => $this->user->name]);
}
}
I combine notification and mailable, because laravel 5.3 not support bcc
It works, but there is one shortcoming. There is no bcc on the email sender. For example, there are 3 emails of bcc. It should appear in the sender's email (If I click sent mail on the gmail and click the detail, Should there exist email bcc. But there is no email bcc)
I setting my sender email in env like this :
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=****@gmail.com
MAIL_PASSWORD=****
MAIL_ENCRYPTION=tls
How can I display bcc on the sender email(on the sent mail)?
Update :
I will add details of my problem
If I sending the mail through gmail like this :
Then I check on sent mail menu on gmail from email sender, the result like this :
There looks like bcc email
If I sending the mail from Laravel with my code above, the result :
I check on the sent mail menu from email sender, the result like this :
There looks like no email bcc
What I want is: I want to display bcc email on the sender's email on laravel
How can I do it?
This won't be possible.
Laravel uses SwiftMailer for SMTP mail. When you send an email with a list of addresses in the BCC field, SwiftMailer actually breaks up that list and sends each address an individual email.
So, instead of sending one email with the header
BCC: test1@gmail.com, test2@gmail.com, test3@gmail.com
, SwiftMailer will send three separate emails with the headersBCC: test1@gmail.com
,BCC: test2@gmail.com
, andBCC: test3@gmail.com
, respectively.Since the email you receive in Gmail does not have a list of addresses in the
BCC
header, it cannot show you the list.Now, I said it's not possible, but technically, if you wanted, you could fork the SwiftMailer repository, update the code to not split the BCC recipients into separate emails, and then figure out how to get Laravel to use your customized version of SwiftMailer, but I highly doubt that would be worth the effort.