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
And my email code is:
class PdfTestMail extends Mailable
use Queueable, SerializesModels;
* 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');
'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.