douluchuo0801 2019-04-23 23:54
浏览 38

调度发送多个排队的邮件

I want to bulk send emails to many (around 300-600) mails using laravel scheduler, for this purpose I created a command to run along with laravel's task scheduler.

As for my mail API, I'm using laravel's integratin of the Mailgun API, Mailgun lets you send thoushands of them.

I also want to run the mail sending through a queue, afaik using a queue is specially for performance heavy tasks such as sending mail.

As for my questions, is this a good, performant way to send multiple mails with laravel scheduler?

Will each of my mails be properly sent to the queue for dispatching?

When I run php artisan schedule:run òn my local dev machine (Windws) I get the following message:

C:\xampp\htdocs\dtcburger.com>php artisan schedule:run
Running scheduled command: "C:\xampp\php\php.exe" "artisan" App\Console\SendWeeklyMail1 > "NUL" 2>&1

But nothing happens after that, I haven't received any emails.

My command for sending mails:

<?php
namespace App\Console\Commands;


use Illuminate\Console\Command;
use Mail;
use App\Models\Event;
use App\Models\Discount;
use App\Models\General;
use App\Models\Sub;
use App\Mail\weekly\WeeklyMail1;


class SendWeeklyMail1 extends Command
{


    protected $signature = 'emails:weekly';
    protected $description = "What's new this week? send weekly emails to subbed users";


    public function __construct()
    {
        parent::__construct();
    }


    public function handle()
    {

        $emails = [ 'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com', 
        'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com',
        'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com',
        'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com', 
        'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com', 
        'zipizape@gmail.com', 'zipizape@gmail.com', 'zipizape@gmail.com' ];

        $mailData = [
            'subject' => 'Últimas novedades en '.env('APP_NAME'),
            'events' => $events,
            'discounts' => $discounts,
        ];

        foreach ($emails as $email)
        {
            Mail::to( $email )->queue(new WeeklyMail1($mailData));
        };
    }


}

Kernel file:

protected $commands = [
        'App\Console\Commands\SendWeeklyMail1',
        'App\Console\Commands\SendBulletinMail1',
    ];


    protected function schedule(Schedule $schedule)
    {
        $schedule->command(SendWeeklyMail1::class);
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 优质github账号直接兑换rmb,感兴趣伙伴可以私信
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办
    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)