A
A
Andr Lw12015-08-18 12:00:06
Laravel
Andr Lw1, 2015-08-18 12:00:06

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);
    }

Tell me how to solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Tikhonov, 2015-08-18
@Keyon

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

A
Alexey Ukolov, 2015-08-18
@alexey-m-ukolov

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 question

Ask a Question

731 491 924 answers to any question