从排队的事件处理程序发送电子邮件
Send email from queued event handler
我将 Lumen 5.1 和 Redis 用于队列。我有一个非常标准的事件处理程序,应该发送电子邮件:
<?php
namespace App\Handlers\Events;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Events\UserHasRegistered;
use Illuminate\Contracts\Mail\Mailer;
class SendWelcomeEmail implements ShouldQueue
{
protected $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public function handle(UserHasRegistered $event)
{
$user = $event->user;
$this->mailer->raw('Test Mail', function ($m) use ($user) {
$name = $user->getFirstName().''.$user->getLastName();
$m->to($user->auth()->getEmail(), $name)->subject('This is a test.');
});
}
}
不使用ShouldQueue
界面时发送邮件。但是当我将事件处理程序推送到队列时(即使用 ShouldQueue
接口),电子邮件没有发送,我也没有收到任何错误消息。
您有解决或调试这个问题的想法吗?
这不是错误,只是意外行为。
我在 Windows 上使用 Xampp 和 php mail
开发驱动程序。由于某种原因,排队的邮件没有保存在 Xampp 目录中的默认 mailoutput
文件夹中。而是在 Lumen 目录中自动创建了一个新的 mailoutput
文件夹。
在那里我找到了所有错过的邮件。 :)
我将 Lumen 5.1 和 Redis 用于队列。我有一个非常标准的事件处理程序,应该发送电子邮件:
<?php
namespace App\Handlers\Events;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Events\UserHasRegistered;
use Illuminate\Contracts\Mail\Mailer;
class SendWelcomeEmail implements ShouldQueue
{
protected $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
public function handle(UserHasRegistered $event)
{
$user = $event->user;
$this->mailer->raw('Test Mail', function ($m) use ($user) {
$name = $user->getFirstName().''.$user->getLastName();
$m->to($user->auth()->getEmail(), $name)->subject('This is a test.');
});
}
}
不使用ShouldQueue
界面时发送邮件。但是当我将事件处理程序推送到队列时(即使用 ShouldQueue
接口),电子邮件没有发送,我也没有收到任何错误消息。
您有解决或调试这个问题的想法吗?
这不是错误,只是意外行为。
我在 Windows 上使用 Xampp 和 php mail
开发驱动程序。由于某种原因,排队的邮件没有保存在 Xampp 目录中的默认 mailoutput
文件夹中。而是在 Lumen 目录中自动创建了一个新的 mailoutput
文件夹。
在那里我找到了所有错过的邮件。 :)