Laravel mail with attachment gives fopen(): null bytes error


I am trying to send an email with a pdf file attached to it.
I checked and the file does exist at the path. I can open it aswell.
I tested if i can download the file with the download function of the storage facade and that also worked.

However when i try it in a queued email, it fails everytime after waiting about 20 seconds.
This is the error i got:

ValueError: fopen(): Argument #1 ($filename) must not contain any null bytes in C:UsersGebruikerPhpstormProjectsFuegoWebsitevendorswiftmailerswiftmailerlibclassesSwiftByteStreamFileByteStream.php:129
Stack trace:

And my email code is:


namespace AppMail;

use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
use IlluminateSupportFacadesApp;
use IlluminateSupportFacadesStorage;

class PdfTestMail extends Mailable
    use Queueable, SerializesModels;

    public $orderId;
    public $text;

     * Create a new message instance.
     * @return void
    public function __construct($orderid, $text)
        $this->orderId = $orderid;
        $this->text = $text;

     * Build the message.
     * @return $this
    public function build()
        $file = Storage::disk('private')->get("factuur_order_".$this->orderId.'.pdf');
        return $this->text('emails.notifyAdmin')
            ->subject('Orderbevestiging #'.$this->orderId)
            ->attach($file, [
                'as' => 'factuur.pdf',
                'mime' => 'application/pdf'


I tried to attach the pdf in multiple ways, including the direct output of the barryvdh/dompdf package i use to generate a pdf.
nothing works and i have no idea why.

Source: Laravel

Categorised as dompdf, email, laravel, laravel-mail, pdf Tagged , , , ,


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us