0

When I send a Multipart mail, HTML view renders correctly but when I activate plain text view it doesn't render accents. How could I send accents in plain text mail using Laravel?

Method used to send mail

Mail::send(['html.blade.php', 'text.txt'], $data, $callback);

Sending áéíóú through a form results in:

HTML

áéíóú

Plain Text

áéíóú

Here's the text view content:

text.blade.php

Information Request
====================================================

{{ $user_message }}

--
{{ $name }}
{{ $email }}

** This mail was sent from mysite.com **

And I'm retrieving information from the controller in this way:

WelcomeController.php

public function contact(ContactFormRequest $request)
{
  $data = array(
    'name' => $request->get('name'),
    'email' => $request->get('email'),
    'phone' => $request->get('phone'),
    'user_message' => $request->get('message')
  );

  Log::info('DEBUGGING $data['user_message']);

  \Mail::send(['emails.html', 'emails.text'], $data,
    function($message) use ($data) {
    $message->from($data['email'], $data['name']);
    $message->to('info@mysite.com', 'Webmaster / My Site')
      ->subject('Info Request');
  });
}

When I enter áéíóú on the form. Log::info returns áéíóú

user2069112
  • 91
  • 1
  • 5
  • 1
    I've tried what you described and it works fine for me. But then again I just placed the `áéíóú` in a view file and sent that. Where are those HTML entities coming from? Are they part of some data fetched from the database? Please post the text view file. – Bogdan Nov 11 '15 at 22:46
  • Can you provide code from html.blade.php? Did your html.blade.php has utf-8 meta tag: If you use htmlentities to output data, make sure it looks like this: htmlentities($str, ENT_QUOTES, "UTF-8"); Also check this answer: http://stackoverflow.com/questions/30442687/how-to-override-default-escape-function-of-blade-in-laravel-5/30443736#30443736 ... could be helpfull – gandra404 Nov 18 '15 at 10:31
  • @Bogdan data is captured using a form. I edited the question with the text view file. – user2069112 Nov 19 '15 at 21:03
  • Btw, placing áéíóú directly on the view do work. But when they come from the contact form they're displayed as html entity. @gandra404 tried `Blade::setEchoFormat` but it still not working – user2069112 Nov 19 '15 at 21:24

2 Answers2

0

Try {!! $var !!} instead of {{ $var }}.

{{ }} in a blade template runs htmlentities() before displaying.

See here for more information: https://laravel.com/docs/5.1/blade#displaying-data

Phylu
  • 1
  • 1
-1

Put this in header

<meta http-equiv="Content-Type"  content="text/html charset=UTF-8" />
José Lozano Hernández
  • 1,813
  • 1
  • 17
  • 21