Answer the question
In order to leave comments, you need to log in
How to solve: Throws an error when sending Laravel send mail in a foreach loop?
Good afternoon!
I use Mailgun to send messages to the mail, the site is made on Laravel 4.2
I need to send one letter to several recipients, but after a while the site gives a 504 Gateway Time-out error.
foreach($users_email as $u_email){
$data['c_email'] = $u_email;
Mail::send('emails.subscribes-everyweek', $data, function($message) use ($u_email, $subject)
{
$message->from('[email protected]', 'Godevment - курсы, тренниги и бесплатное обучение :)');
$message->to($u_email->email)->subject($subject);
});
sleep(1);
}
Answer the question
In order to leave comments, you need to log in
Look towards Queues . You apparently have a lot of users to whom you are trying to send an email, and it is logical that the server returns a 504 error. Try increasing the max_execution_time parameter even more
You after each letter force the script to wait 1 second. If there are, for example, 60 letters and a timeout of nginx a minute, the client will eventually receive a response that the timeout has expired. This is logical.
That's right - send emails in a background task.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question