我正在尝试发送多封电子邮件,但返回了此类错误:
预期的响应代码354,但得到的代码为“ 550”,并显示消息“ 550 5.7.0” 未采取请求的操作:每秒电子邮件过多”
$reciverss = array_merge($admins, $workers); // finalizing my queries and joining two arrays in one
// getting input data
$details = array(
'body' => $request->input('body'),
'subject' => $request->input('subject'),
);
// getting receivers email addresses from my merged array and try to send input data to them as email
foreach($reciverss as $receive){
Mail::to($receive->email)->send(new PICMAIL($details));
}
这是我的$rereciverss
数据的样子:
[{email: "admin@admin.com", username: "admin", userId: 1},…]
0: {email: "admin@admin.com", username: "admin", userId: 1}
1: {email: "employee@employee.com", username: "employee", userId: 2}
2: {email: "non-employee@employee.com", username: "non employee", userId: 3}
基本上,我需要将电子邮件发送出去才能向他们发送电子邮件,但它返回我上面提到的错误。
有什么主意吗?
答案 0 :(得分:3)
根据您的错误提示
每秒电子邮件太多
您可以在电子邮件中添加一些延迟,然后重试,或者使用Job throttling处理这种情况。 看看sleep()函数
foreach($reciverss as $receive){
sleep(30);
Mail::to($receive->email)->send(new PICMAIL($details));
}
答案 1 :(得分:1)
在这里使用队列是最好的决定,并调度它。
foreach($reciverss as $receive){
MailQueueClass::dispatch(with_your_data);
}
<?php
namespace App\Jobs\Email;
use App\Mail\InvoiceCreated;
use App\Models\Order\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Mail;
class SendInvoice implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private your_variable;
/**
* Create a new job instance.
*
* @param $order_id
*/
public function __construct($your_variable1,$your_variable2)
{
$this->your_variable1 = $your_variable1;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Mail::to($your_variable1)->send(new PICMAIL($your_variable2));
}
}
答案 2 :(得分:0)
请尝试这个。
<properties>
<java.version>11</java.version>
</properties>