I am trying to send bulk emails (approx. 5000) to subscriber. I am sending all emails in BCC and Mail::queue(). I am running command from console to trigger emails.
try {
$bccEmails = ['test@test.com', 'xyz@gmail.com', 'abc@gmail.com', 'anb@hotmail.com', 'xyzz@yahoo.com'];
Mail::queue('Emails.Newsletter', $data,
function ($message) use ($bccEmails, $subject) {
$message->from('no-reply@test.com', 'xyz.com')
->bcc($bccEmails)
->replyTo($this->adminEmail, $this->adminName)
->subject($subject);
});
} catch (Exception $ex) {
Log::info("Email sending error: ".$ex->getMessage());
}
But i am getting error as below:
"Expected response code 250 but got code "421", with message "421 too many messages in this connection"
-
How to resolve above issue ?
-
What is the best way to send bulk emails to users ?
Second question: which one is the best approach. As mentioned above Mail:queue or Mail:send in loop as below:
$toEmails = ['test@test.com', 'xyz@gmail.com', 'abc@gmail.com', 'anb@hotmail.com', 'xyzz@yahoo.com'];
foreach ($toEmails as $key => $email) {
try {
Mail::send('Emails.Newsletter', $data,
function ($message) use ($email, $subject) {
$message->from('no-reply@test.com', 'xyz.com')
->to($email)
->replyTo($this->adminEmail, $this->adminName)
->subject($subject);
});
} catch (Exception $ex) {
Log::info("Email sending error: ".$ex->getMessage());
// If failed continue sending next email
}
}
Using: Laravel 5.2, Shared hosting
Please help on this. Let me know if further details is required.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire