Nosean
7 months ago

Send Email with Jobs

Posted 7 months ago by Nosean

hi Guys I'm desperately looking for a solution to my problem. I'm trying to send multiple mail per queue job.

My controller:

public function sendjob(Request $request) {

        $date = $request->lieferdatum;
        $today  = Carbon::createFromFormat('d.m.Y', $request->lieferdatum);
        $yesterday = date_format($today->subDay(), 'd.m.Y');



        foreach($request->user_id as $kto) {

            $users = DB::table('users')
                ->where('Kto', '=', $kto)
                ->first();

            $data = Array(
                'date' => $date,
                'yesterday' => $yesterday,
                'user_name' => $users->Name,
                'user_name2' => $users->Name2,
                'user_adress' => $users->LieferStrasse,
                'user_zip' => $users->LieferPLZ,
                'user_city' => $users->LieferOrt,
                'user_email' => $users->EMail,
                'user_kto' => $users->Kto
            );

        }

        $details = $data;

        dispatch(new SendRememberEmailJob($details))->delay(now()->addSecond(5));

    }

My Job

<?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 App\Mail\SendRememberEmail as SendRememberEmail;
use Mail;

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


    protected $details;

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

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Mail::to($this->details['user_email'])->send(new SendRememberEmail());
    }
}

My Blade


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Bestellerinnerung</title>
</head>
<body>


TEST NACHRICHT

</body>
</html>

If I now execute the job via artisan queue: work, emial will not be sent and the entries in the job table will not be deleted either. Does anyone see the error ???

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