I have to update from 5.1 to 5.4
This was code for mail with`5.1
Mail::queue('emails.welcome_client', compact('user', 'userPassword'), function ($message) use ($user, $adminEmails) {
$message->subject('Welcome to Enterprise Solutions!');
$message->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'));
$message->to($user->email);
foreach($adminEmails as $adminEmail) {
$message->bcc($adminEmail);
}
});
I have to change from Laravel 5.1 to 5.4 so I create object mail
here it is
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ClientMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public $user;
// protected $content;
public function __construct($user)
{
$this->content = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from(('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'))
->subject('Welcome to Enterprise Solutions!')
->view('emails.welcome_client');
}
}
and in controller I do this
Mail::to($user->email)
->bcc($adminEmail)
->queue(new ClientMail($adminEmails));
when I try to run I get this error: Undefined $adminEmail
. How I can fix this problem?
Try this one:
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ClientMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->from(('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'))
->subject('Welcome to Enterprise Solutions!')
->view('emails.welcome_client');
return $this;
}
}
And in Controller call:
Mail::to($user->email)->bcc($adminEmails)->queue(new ClientMail());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With