Search code examples
phpamazon-web-servicesamazon-ec2laravel-5.1beanstalkd

Laravel - Bug in sending email to wrong user


I'm using laravel 5.1. AWS EC2 service, ubuntu OS.

I've created a command that sends emails to a number of users. Lets say I have this sample code:

foreach($users as $user) {
    $data = $user->toArray();
    $data['subject'] = "This is subject";
    Mail::queue('emails.email_content', $data, function ($message) use ($data) {
        $message->subject($data['subject']);
        $message->to($data['email']);
    });
}

In email_content.blade.php lets say I have this code

Hi {{ $first_name . ' ' . $last_name }}

I used beanstalkd as my queue driver. And use supervisor for monitoring. In my .env file I have this:

CACHE_DRIVER=file
SESSION_DRIVER=database
QUEUE_DRIVER=beanstalkd

But some users are complaining that they're receiving the wrong emails because the name is wrong, sometimes even the subject is wrong. And I'm sure getting the correct $users. What am I doing wrong here? Is it possible that the email are cached or something like that?


Solution

  • My problem has been resolved, it seems that I have to run php artisan queue:restart whenever I changed my email view content.