D
D
Dmitry2019-10-20 09:01:40
Email
Dmitry, 2019-10-20 09:01:40

Why is the sender's encoding wrong?

there is a constant in laravel .env file When sending mail
MAIL_FROM_NAME="Имя_отправителя_русскими_буквами"

Mail::send('emails.test', $data['content'], function($message) use ($data)
        {
            $message->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'));
            $message->to($data['to']);
            $message->subject($data['subject']);
        });

a letter arrives in the mailbox, in which FROM WHOM it comes in scribbles:
?������ �������� ������?
Tell me how to fix the encoding?
I can't figure out why this is if the .env file is in UTF-8 though?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis, 2019-10-20
@notwrite

Non-Latin characters in from must be encoded in base64, specifying the encoding

W
wisgest, 2019-10-20
@wisgest

For example, an email from Toster about your question has the title
moreover, if the letter is saved to a file and opened in a text editor, then this header looks like

From: =?utf-8?B?0KLQvtGB0YLQtdGAIOKAkyDQstC+0L/RgNC+0YHRiyDQuCDQvtGC0LLQtdGC?=
 =?utf-8?B?0Ys=?= <[email protected]>

(Actually, the header here is split into two lines due to the line length limit in the mail message, but as far as I can tell, it is not too strict and the letter would have reached even if it was one line).
Try encoding "Имя_отправителя_русскими_буквами"directly in the .env file like this ,
or on the fly when called $message->from()(seems to use base64).

V
Vladimir Kokhan, 2019-10-20
@SkazochNick

I always write like this

Mail::send('email.users',  function ($message) use ($email) {
            $message->from(env('MAIL_ADMIN', env('MAIL_FROM_NAME')), 'Спасибо за заказ');
            $message->to($email, 'Сообщение о заказе')->subject('Сообщение о заказе');
        });

and everything is displayed normally without any encodings

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question