project = $project; // Store form data $this->pdf = $pdf; // Store the generated PDF } /** * Get the message envelope. * * @return \Illuminate\Mail\Mailables\Envelope */ public function envelope() { return new \Illuminate\Mail\Mailables\Envelope( subject: 'New Project' // Subject of the email ); } /** * Get the message content definition. * * @return \Illuminate\Mail\Mailables\Content */ public function content() { return new \Illuminate\Mail\Mailables\Content( view: 'emails.form_submission', // The email body view with: [ 'project' => $this->project, // Pass form data to the view ] ); } /** * Get the attachments for the message. * * @return array */ public function attachments(): array { // Get the raw PDF content using output() method $pdfContent = $this->pdf->output(); // This is the raw PDF binary content // Attach the PDF using attachData() method (not fromData()) return [ // Using attachData to attach the raw binary PDF content Attachment::fromData( fn() => $pdfContent, // Passing raw binary content as closure 'Report.pdf' // Name of the PDF file )->withMime('application/pdf'), // Set MIME type as application/pdf ]; } }