php - Laravel mail with accent in subject

254

I have a service sending mails.

My problem is the subject in the title contains accents, but they're not showing up in the mails.

When for example I put in:

->subject ( 'Olvidó de Contrase$ntildea' );

In the mail the subject appears like this 'Olvid de Contrase'

It doesn't show the ó and ñ letters.

Any help is much appreciated.

848

Answer

Solution:

Ok I find a solution, and is this

->subject(utf8_encode( 'Olvidó de Contraseña' ));

Works Perfect! Thanks for help!

998

Answer

Solution:

Subject is an email header. And headers may only contain ASCII characters.

So you have to encode your headers with base64 (B) and quote-printable (Q).

$to = '[email protected]';
$subject = 'Subject with non ASCII ó¿¡á';
$message = 'Message with non ASCII ó¿¡á';
$headers = 'From: [email protected]'."\r\n"
.'Content-Type: text/plain; charset=utf-8'."\r\n";
mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, $headers);

Read more about RFC 1342 (Representation of Non-ASCII Text in Internet Message Headers): http://datatracker.ietf.org/doc/rfc1342/

People are also looking for solutions to the problem: PHP/PDO Error: SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.