I'm trying to get new lines in my email template, but for some reason it doesn't work.
My Controller:
$content = $postData['name']. ' \n \n ' .$postData['address'];
$message = \Swift_Message::newInstance()
->setSubject('test')
->setFrom($session->get('email'))
->setTo('myemail@gmail.com')
->setBody(
$this->renderView(
'email.html.twig',
array('content' => $content)
),
'text/html'
)
;
My twig:
{{ content | nl2br }}
The result I get:
name \n \n address
In stead of '\n' I also tried using '\r\n' and '< br />', but no new lines neither in the email I get.
This should do it: .' \n \n '.
to .PHP_EOL.PHP_EOL.
.
Or use ."\r\n".
directly as @Álvaro González mentioned.
The difference is '
-> "
.