我试图将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相同
路线::得到(' sendbasicemail',' MailController @ basic_email&#39);
并在queue.php / mail.php / .env中设置所有内容 如队列驱动程序:数据库 和所有邮件凭证 并且我收到MailController.php中找不到MailJob类的错误 我试过这个
use App/Jobs/MailJob;
仍然有同样的错误 我是Laravel的一个非常乞丐 并请告诉我我的代码中的所有错误