Làm sao để gửi mail không đồng bộ trong Laravel?
Làm sao để gửi mail không đồng bộ trong Laravel?
Gửi mail trực tiếp trong request làm người dùng phải chờ SMTP/API phản hồi (có thể vài giây, và lỗi mạng làm hỏng request). Giải pháp là đưa việc gửi mail vào queue.
ShouldQueueclass OrderConfirmed extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public function __construct(public Order $order) {}
}
Mail::to($user)->send(new OrderConfirmed($order)); // tự động vào queue
queue() hoặc later()Mail::to($user)->queue(new OrderConfirmed($order));
Mail::to($user)->later(now()->addMinutes(10), new ReminderMail($order));
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.