Laravel mail queue break cyrillic sender's name encode

Viewed 83

The problem is that when I send an email synchronously everything works fine.

Mail::to(env("MAIL_TO"))->send(new MortgageApplication($validatedReqest['name'], $validatedReqest['phone']));

enter image description here

then i use the mail queue, cyrillic string in env return incomprehensible value.

Mail::to(env("MAIL_TO"))->queue(new MortgageApplication($validatedReqest['name'], $validatedReqest['phone']));

get the sender's name like this enter image description here

I found what was the problem. Then i use env variables in MortgageApplication class and send without queue this work fine.

public function build()
{
    var_dump(env('MAIL_FROM_NAME'));
    var_dump(mb_detect_encoding(env('MAIL_FROM_NAME')));
    return
        $this->subject('test')
        ->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'))
        ->view('mortgage-application')
        ->with([
            'name' => $this->name,
            'phone' => $this->phone,
        ]);
}

And env('MAIL_FROM_NAME') return needed string
mb_detect_encoding(env('MAIL_FROM_NAME')) return 'UTF-8'

If i use queue env variables breaks.

And env('MAIL_FROM_NAME') return ���� �� �������� mb_detect_encoding(env('MAIL_FROM_NAME')) return NULL

Why env return incomprehensible value when mail send in queue. And how can solve the issue?

Temporary solution : put env variables in MortgageApplication constructor

Mail::to(env("MAIL_TO"))->queue(new MortgageApplication($validatedReqest['name'], $validatedReqest['phone'], [
            'name' => env('MAIL_FROM_NAME'),
            'address' => env('MAIL_FROM_ADDRESS')
        ]));

MortgageApplication class

public function build()
{

    return
        $this->subject('test')
        ->from($this->from['address'], $this->from['name'])
        ->view('mortgage-application')
        ->with([
            'name' => $this->name,
            'phone' => $this->phone,
        ]);
}
0 Answers
Related