在laravel中发送大量电子邮件

问题描述 投票:3回答:1

晚安

问题1.-

我需要为每个创建的事件发送超过1000封电子邮件,为此我使用队列(如Laravel的文档所述),但在发送电子邮件时我必须等到发送所有电子邮件才能返回到控制面板的视图

这是我发送电子邮件的NewsEvents.php控制器中的“存储”功能

 public function store(Request $request)
{
    $attributes = request()->validate(News::$rules, News::$messages);

    $news = $this->createEntry(News::class, $attributes);

    //queue for sending emails 
     $this->dispatch(new Nevent($news));


    return redirect_to_resource();
}

工作“Nevent.php”的“句柄”功能

 public function handle()
{
    //   
     $users=User::where('tipo_user','user')->get();                  
         foreach($users as $user)
         {
             $user->notify(new EventCreated($this->news));
             echo 'enviado correo';
             Informe::create([
                'event_id' => $this->news->id,
                'total' => '1',
                'tipo' => 'invitacion',
                'dst_id' => $user->id,
                'estado' => 'correcto',
            ]);

         }
}

可能是什么问题呢?

问题2.-

我怎么能每分钟发送一封电子邮件?因为在发送所有电子邮件时,我的服务器回复了以下消息:

域mu.edu.fi已超过每小时允许的最大电子邮件数(100/100(100%))。消息将在稍后重新尝试

php laravel laravel-5
1个回答
1
投票

如果您使用Redis服务器来管理作业,Laravel会为速率限制API提供一个简单的API

Redis::throttle('your job id')->allow(10)->every(60)->then(function () {
// Job logic...
}, function () {


return $this->release(10);
});

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.