drwho's avatar
Level 1

Laravel, mail in queue don't work

Hello !

I have made a website with laravel 5.5. I have a page where I can upload a csv file with users email and I send them an invitation email. To do this, I have created a new Job . In localhost, everything work and email are sent but recently I have deployed my website on ovh and things started to goes wrong :

The reset password email works. If I read my CSV file and send email without queue it works. But when I read my CSV file and send email using my Job, the job finished without errors but email are not sent.

So after this I decided to change mail driver to log and see what happened : email are written in logs but when I rechange my driver to mail, nothing happened again.

Here my mail configuration (.env)

QUEUE_DRIVER=database
MAIL_DRIVER=mail
MAIL_HOST=smtp.mydomain
MAIL_PORT=587
MAIL_USERNAME=username@mydomain
MAIL_PASWWORD = ****
MAIL_ENCRYPTION=false
pretend=false

My controller :

$this->dispatch(new LinkUsers($ELO_task)); //* new job here

My Job (only the part where i send email ) :

Mail::getSwiftMailer()->registerPlugin(new \Swift_Plugins_AntiFloodPlugin(50, 61));
                if ($BOOL_new1){
                    Mail::to($ELO_usr1->email)->send(new InvitationMail($ELO_usr1->name,$ELO_usr1->fname,$ELO_usr1->id));
                }else{
                    Mail::to($ELO_usr1->email)->send(new RequestParticipationMail($ELO_usr1->name,$ELO_usr1->fname));
                }
                if ($BOOL_new2){
                    Mail::to($ELO_usr2->email)->send(new InvitationMail($ELO_usr2->name,$ELO_usr2->fname,$ELO_usr2->id));
                }else{
                    Mail::to($ELO_usr2->email)->send(new RequestParticipationMail($ELO_usr2->name,$ELO_usr2->fname));
                }

RequestParticipationMail.php :

0 likes
2 replies
drwho's avatar
Level 1

InvitationMail .php :


<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class InvitationMail extends Mailable 
{
    use Queueable, SerializesModels;
    /**
     * @var
     */
    public $name;
    /**
     * @var
     */
    public $fname;


    public $id;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($name, $fname,$i)
    {
        //
        $this->name = $name;
        $this->fname = $fname;
        $this->id = $i;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this
            ->from("noreply@mydomain")
            ->markdown('mail.invitation');
    }
}


RequestParticipationMail.php :


<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class RequestParticipationMail extends Mailable 
{
    use Queueable, SerializesModels;

    /**
     * @var
     */
    public $name;
    /**
     * @var
     */
    public $fname;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($name, $fname)
    {
        $this->name = $name;
        $this->fname = $fname;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this
            ->from("noreply@mydomain")
            ->markdown('mail.notificationNewEvaluation');
    }
}



I'm stuck with this for days

Please or to participate in this conversation.