您好我正在使用mailable并使用队列但是当我使用php artisan queue:listen
并发送邮件时它没有像预期的那样工作,我确实收到了mailtrap上的电子邮件,但是没有留言我的控制台。我尝试先发送邮件然后使用我的命令,但它没有我的命令。并且它不需要一段时间,因为它立即发送是我的代码
Controller.php这样
use Illuminate\Support\Facades\Mail;
use App\Mail\testmail;
class Controller extends Controller{
public function email($email, Request $request){
$emailuser = $request->input('email');
$message = $request->input('bericht');
mail::to($email)->queue(new testmail($emailuser, $message));
}
}
testmail.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class testmail extends Mailable
{
use Queueable, SerializesModels;
public $emailuser;
public $message;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($emailuser, $message)
{
$this->emailuser = $emailuser;
$this->message = $message;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('email.mail');
}
}
mail.blade.php
@component('mail::message')
{{ $emailuser }}
{{ $message }}
Thanks,<br>
{{ config('app.name') }}
@endcomponent
有没有人知道如何解决这个问题,因为我需要它来延迟我的应用程序
答案 0 :(得分:-2)
使用作业而不是Maillable,并在句柄功能的该作业中记下代码以在该作业中发送电子邮件 因为 - :
$job = (new SendWelcomeEmail($activation->code,$user))->onQueue('default');
和作业文件SendwelcomeEmail想要关注 - :
<?php
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;
use App\Jobs\Job;
use Mail;
class SendWelcomeEmail extends Job implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
protected $activation_code;
protected $user;
public function __construct($activation_code,$user)
{
$this->activation_code=$activation_code;
$this->user=$user;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try{
$user=$this->user;
Mail::send('emails.user.register', ['activation_code' => $this->activation_code,'user'=>$this->user], function ($m) use ($user) {
$m->to($user->email,$user->first_name." ".$user->last_name)
->subject(trans('emails.USER_REGISTER_SUBJECT',['project'=>trans('project.project_name')]));
});
\Log::useDailyFiles(storage_path().'/logs/user-registration/success/'.date('Y-m-d').'.log');
\Log::info('Welcome Email Send to-:'.$user->email);
}catch(Exception $ex){
\Log::useDailyFiles(storage_path().'/logs/user-registration/error/'.date('Y-m-d').'.log');
\Log::error($ex->getMessage());
\Log::error("Line Number->".$ex->getLine());
}
}
}