email = $email; $this->template = $template; $this->posts = $posts; $this->title = $title; $this->department = $department; $this->count = $count; $this->debug = $debug; $this->debugText = $debugText; } /** * Execute the job. * * @return void */ public function handle(Mailer $mailer) { $email = $this->email; $template = $this->template; $posts = $this->posts; $title = $this->title; $department = $this->department; $count = $this->count; $debugText = $this->debugText; if($this->debug) { echo "Sende Bericht an: Stadt Eppingen\n"; } $users = User::select('email') ->join('user_tag as user_tag', function ($join) { $join->on('users.id', 'user_tag.user_id'); }) ->join('tags as tags', function ($join) use($department) { $join->on('tags.id', 'user_tag.tag_id') ->where('tags.type', 'abteilung') ->where('tags.name', $department); }) ->join('user_tag as user_tag2', function ($join) { $join->on('users.id', 'user_tag2.user_id'); }) ->join('tags as tags2', function ($join) use($department) { $join->on('tags2.id', 'user_tag2.tag_id') ->where('tags2.type', 'benachrichtigung') ->where('tags2.name', 'Veröffentlichungen'); }) ->get(); $emailFrom = config('mail.from.address'); $emailCC = array(); if(count($users)) { foreach($users as $user) { $emailCC[] = $user->email; } } /** / // Nur für Testzwecke // if($department == 'Eppingen') { $title .= "EMPFÄNGER: ".implode(', ', $emailCC)." - ".$email." => FROM: ".$emailFrom; $email = "m.glietsch@kortec.de"; $emailFrom = "mail@marco-glietsch.de"; $emailCC = ['glietschie@gmx.de']; } else { return; } /**/ $mailer->send($template, ['publications' => $posts, 'debugText' => $debugText], function($message) use($email, $emailFrom, $emailCC, $department, $count, $title){ $message->to($email) ->from($emailFrom, "Feuerwehr Eppingen - Abteilung $department") ->cc($emailCC) ->subject("$title vom ".Carbon::now()->format('d.m.Y')." ($count)"); // ->subject("Feuerwehr Eppingen: Abteilung $department - $title vom ".Carbon::now()->format('d.m.Y')." ($count)"); }); } }