Nosean
11 months ago

Queue Job pass the mail::to Email Adress

Posted 11 months ago by Nosean

I try to send many emails to different recipients.

my dispatch function:

    public function sendEmail () {
        $ users = User :: all () -> take (5);
        foreach ($ users as $ user) {
            $ data ['email'] = $ user-> email;
            dispatch (new SendEmailJob ($ data));
        }
       
    }

and my job class:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;
use App\Mail\SendMailable;


class SendEmailJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;


    protected $data;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Mail::to('[email protected]')->send(new SendMailable());
    }
}

how do I tell the mail :: to method with which a different email address should be used again and again.

thanks

Please sign in or create an account to participate in this conversation.