I want to send email in laravel. 2 user get different email content. So, here is my code.
TransactionController.php
use App\Mail\MailFruitCustomer;
use App\Mail\MailFruitSeller;
$data = array(
'fruitid' => 'F01',
'fruitname' => 'Banana',
'customercode' => 'B2345',
'sellercode' => 'S9546'
);
Mail::to([email protected])->send(new MailFruitCustomer($data));
Mail::to([email protected])->send(new MailFruitSeller($data));
MailFruitCustomer.php (In Mail folder)
public function __construct($data){
$this->data = $data;
}
public function build(){
$result = $this->from('[email protected]')
->subject('Customer New Transaction')
->markdown('emails/customerreceipt')
->with('data', $this->data);
return $result;
}
MailFruitSeller.php (In Mail folder)
public function __construct($data){
$this->data = $data;
}
public function build(){
$result = $this->from('[email protected]')
->subject('Seller New Transaction')
->markdown('emails/sellerreceipt')
->with('data', $this->data);
return $result;
}
customerreceipt.blade.php
@component('mail::message')
Customer Receipt Detail
Fruit ID: {{ $data['fruitid'] }}
Fruit Name: {{ $data['fruitname'] }}
Customer Code: {{ $data['customercode'] }}
Thank you.<br>
@endcomponent
sellerreceipt.blade.php
@component('mail::message')
Seller Receipt Detail
Fruit ID: {{ $data['fruitid'] }}
Fruit Name: {{ $data['fruitname'] }}
Seller Code: {{ $data['sellercode'] }}
Thank you.
@endcomponent
It is working and both user get email with different content. But the process take longer time. Is there any method of mail in laravel that i could apply?
Any help will be grateful. Thank you.