@ApeWare that's weird, because in a normal php page, not even in laravel, viewing source is showing correctly. I still don't think it's a blade problem. But could be.
Try writing each line to just a text file and see if it works correctly.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
@ApeWare that's weird, because in a normal php page, not even in laravel, viewing source is showing correctly. I still don't think it's a blade problem. But could be.
Try writing each line to just a text file and see if it works correctly.
@Snapey I already tried it with the . character and it works fine.
I tried it with a text mailer and it still is stripping off the leading spaces.
In my core view for text emails, I have a centered footer block. This footer block renders perfectly fine and uses the same strategy I am trying to use for the title.
The only difference is that I am @yield()ing the components but the footer is right in the core. I am going to look into the core and see if there is something inside @yield() that does some trimming or something.
You stated
I already tried it with the . character and it works fine.
Thus it has to do with the space. I bet it would work correctly in writing it to just a raw text file.
I think I found the issue. When you use view components, the component data Laravel does a trim() to the data before merging it into its array; see source.
I am not sure how to work around this yet, but at least I know why it is happening. I don't think view should assume HTML is going to be used exclusively but that is just my opinion.
You can turn that off somewhere, I forget where. And this woks 100% correct
<?php
$out = fopen("list2.txt", "wb");
$nl = "";
$title = "Just a test";
$myline = str_pad( $title, 60, ' ', STR_PAD_BOTH );
fwrite($out, $myline);
fclose($out);
?>
In just native php
Edit:
The settings are in App\Http\Kernel class to turn off trimming.
@jlrdw, yes, the native PHP works, it is Laravel that is trimming component data.
I can handle this manually in the specific mailable I am working on but I will not be able to use Blade components for text versions of emails...unless I can convince Taylor to change this behavior.
Thanks for mentioning App\Http\Kernel I did, for sake of testing, comment that out of the middleware but it did not change the output. I don't think that affects the blade components; will have to look into that middleware to see exactly what it does.
At least as @Snapey said, it wasn't something daft you did. It's a blade thing. Those words he comes up with.
@ApeWare Uses ' ' instead ' ', it's probably work well
Edit -- '&.nbsp;', please remove the dot after '&'
@Mustorze - I don't understand your comment.
You're using ' ' to create this spacing, right? Instead of using ' ', use this code, '&.nbsp;', but for it to work you should remove the '.' after '&'.
This is for a plain text email, so I can't use non-breaking space as the characters would be displayed as plain text.
Humm. now i understand. Then, if your pass these spaces throught a variable, did you tried that?
example:
<?php $spaces = ' '; ?>
{!! $spaces !!}
If I used your sample code, it too would be trimmed.
The issue as stated in a previous reply is:
When you use view components, the component data Laravel does a trim() to the data before merging it into its array; see source.
So as long as I don't use a Blade component it will display. You can see on line 77 in the source that it does a trim. The only way around this, currently, seems to be to avoid generating plain text using component unless you want the text trimmed. I was making a plain text version of an HTML component to be used for Mailables; cant do that if I want to replicate the centering of plain text.
Please or to participate in this conversation.