2

I'm having a strange issue where a standard Laravel notification mail is being filled with extraneous line breaks. It looks like all the line breaks from the html files are converted to <br>s.

Here's an example:

notification

I'm using Laravel 5.7, and it's not a clean install, so it might totally be something related to it. It's a pretty basic app though, with little or no customization. I have always followed the upgrade guides and git commits to keep it updated with the latest changes.

Does anybody have any clue of how to fix this?

Edit: for comparison, here's a portion of the original source:

<tr>
    <td class="header">
        <a href="{{ $url }}">
            {{ $slot }}
        </a>
    </td>
</tr>

and here's the resulting code after Laravel does its things (I've removed the inlined css for readability):

<tr>
<br><td class="header" style="...">
<br><a href="http://localhost:8888" style="..."><br>
            Laravel<br></a><br>
</td>
<br>
</tr>
2
  • Post your code for the notification in order for us to help out further. Dec 12, 2018 at 22:43
  • It's just the basic reset password notification from Laravel, no changes. What part of code would you look at?
    – Alan
    Dec 13, 2018 at 1:20

2 Answers 2

1

Check app/Providers/AppServiceProvider.php you might find something similar to this: Blade::setEchoFormat('nl2br(e(%s, true))');

This will turn your new lines into <br> tags. See nl2br() for more.

0

In my case, the issue was not Laravel, rather it was from my email provider. They automatically convert newline characters in the sent mail to the <br> tag. I used the code below to remove every newline character from my email before sending and it solved the problem.

$html = preg_replace('/\s+/', ' ', trim($html));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.