Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29755

Laravel later method fires emails randomly

$
0
0

I am using laravel admin, and I am trying to send emails at a specific time. I pass this datetime data into the first argument of later method

"date" => Carbon @1576722840 {#543 ▼ date: 2019-12-19 02:34:00.0 UTC (+00:00) }

However, it doesnt work as I expected. it randomly sends emails.

    $form->saved(function (Form $form) {

        if ($form->model()->to === '4') {
            $emails = EmailAddress::all();
        } else {
            $emails = EmailAddress::where('user_type', $form->model()->to)->get();
        }
        $data = ['id' => $form->model()->id, 'title' => $form->model()->title, 'from' => $form->model()->from, 'body' => $form->model()->body, 'date' => $form->model()->schedule_date, 'is_html' => $form->model()->is_html];

        foreach ($emails as $email) {
            $url = URL::signedRoute('unsubscribe',['email_address_id' => $email->id]);
            Mail::to($email)->later($data['date'],new MagazineMail($data,$url));
            SendEmail::dispatch($data, $email);
        }
    });
    return $form;
}

As I understood it, if I want to send a mail at a specific time, I should just pass a datetime into the first argement, so I have no idea why my code does not work.

I made sure my env file is correct and set QUEUE_CONNECTION=database.


Viewing all articles
Browse latest Browse all 29755

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>