mercredi 27 septembre 2017

Know if Mail in queue has been sent Laravel 5.4

I have a webapp built with laravel 5.4. Now I have developed a function that send to all users a comunication.

So i have create a class Mailable:

class Comunication extends Mailable
{
    use Queueable, SerializesModels;

    private $data;
    private $recipient;
    private $fromR;
    private $subjectR;
    private $template;

    public function __construct($template, $data,$recipient,$from,$subject)
    {
        $this->data = $data;
        $this->recipient = $recipient;
        $this->fromR = $from;
        $this->subjectR = $subject;
        $this->viewData = $data;
        $this->template = $template;
    }
    public function build()
    {
        return $this->from($this->fromR)->to($this->recipient)->subject($this->subjectR)->view( $this->template, $this->viewData);
    }

And in my controller I have a function send like:

foreach ($users as $user){
   Mail::queue(new Comunication('mail.comunication', array("user"=>"test"), $user->email, 'mytest@test.it', "subject"));
}

And it works and put a mail in my table Jobs on db, but I would know if is possible check, when I run:

php artisan queue:listen

If mail is real sent or finish in failed jobs.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire