[when send emails shows these error][1]ReflectionException Method App\Mail\Newsletter::__invoke() does not exist
these is my controlledispatch(new Newsletter($emailSubject,$emailBody,$arrayEmails));
these is my email classpublic function build() { return $this->view('emails.newsletter')->subject($this->emailSubject)->with(['msg'=> $this->emailBody]); }
these is my jobs public function handle() { $email = new Newsletter($this->emailSubject,$this->emailBody,$this->arrayEmails); Mail::to($this->arrayEmails)->send($email); }
CodePudding user response:
As I understand, you create a job that in turn create and send the email object.
However, in the controller, you are not dispatching the job, you are dispatch the email object. And the email object doesn't contain either a handle
or __invoke
method so you see the error message.
The solution is to dispatch the job instead of the email.
This design is indeed unnecessary. Pls have a look at Mailables, create a queued mailable, and just send it.