我必须从5.1更新到5.4
这是使用`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);
}
});
我必须从Laravel 5.1更改为5.4 所以我创建了对象邮件
这里是
<?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');
}
}
在控制器中我这样做
Mail::to($user->email)
->bcc($adminEmail)
->queue(new ClientMail($adminEmails));
当我尝试运行时,我收到此错误:Undefined $adminEmail
。我该如何解决这个问题?
答案 0 :(得分:2)
试试这个:
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;
}
}
在Controller调用中:
Mail::to($user->email)->bcc($adminEmails)->queue(new ClientMail());