我正在尝试将我在 laravel 中的普通电子邮件程序转换为使用队列发送电子邮件
这是控制器中的代码(简单邮件代码)>>
public function basic_email(){
$user = DB::select(DB::raw('select emailid from items where created_at = (select max(`created_at`) from items)'));
$content = array('name'=>"Virat Gandhi");
Mail::send(['text'=>'mail'], $content, function($message) use ($user){
$message->from('guptavaishalibdn@gmail.com','Virat Gandhi');
$message->subject('Laravel Basic Testing Mail');
foreach($user as $u){
$message->to($u->emailid);
}
});
echo "Basic Email Sent. Check your inbox.";
}
它工作正常我试图将其转换为队列>>
public function basic_email(){
$user = DB::select(DB::raw('select emailid from items where created_at = (select max(`created_at`) from items)'));
$content = array('name'=>"Virat Gandhi");
$this->dispatch(new MailJob($content,$user));
}
工作代码>>
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class MailJob implements ShouldQueue
{
private $content;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(Content $content, User $user){
$this->content = $content;
$this->user= $user;
}
public function handle(){
Mail::queue(['text'=>'mail'], $content, function($message) use ($user){
$message->from('guptavaishalibdn@gmail.com','Virat Gandhi');
$message->subject('Laravel Basic Testing Mail');
foreach($user as $u){
$message->to($u->emailid);
}
});
echo "Basic Email Sent. Check your inbox.";
}
WEB.PHP 两者都是一样的
Route::get('sendbasicemail','MailController@basic_email');
并在 queue.php/mail.php/.env 中设置所有内容,例如队列驱动程序:数据库和所有邮件凭据,我收到一个错误,即在 MailController.php 中找不到 MailJob 类我试过了
use App/Jobs/MailJob;
仍然有同样的错误我是 Laravel 的初学者,请告诉我我的代码中的所有错误