简体   繁体   English

使用Laravel 5.5异步发送电子邮件

[英]Send emails asynchronously with Laravel 5.5

How could email be sent asynchronously or in a faster way? 如何以异步方式或以更快的方式发送电子邮件?

I made an application with the basic method: 我用基本方法做了一个应用程序:

PHP artisan make: mail demo

Then the view 然后是观点

public function build()
    {
        return $this->view('emails.demo');
    }

Sending the mail 发送邮件

public function index()
    {
        $email = Auth::user()->email;
        Mail::to($email)->send(new DemoMail());
        return view('home');
    }

How could I send emails faster? 我怎样才能更快地发送电子邮件?

Emails can be sent using Laravel's built in queuing methods: 可以使用Laravel的内置排队方法发送电子邮件:

public function index() {
    $email = Auth::user()->email;

    Mail::to($email)->queue(new DemoMail());

    return view('home');
}

In order for this to work, you have to configure your queues first. 为此,您必须先配置队列

Once your queues have been setup, you just need to queues being processed by a background worker using: 一旦设置了队列,您只需要使用后台工作人员处理队列:

php artisan queue:work

This allows your emails to be sent asynchronously without slowing down the page load times for your visitors. 这样可以异步发送电子邮件,而不会减慢访问者的页面加载时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM