Cakepdf output redirect to teh server

I am implementing a newsletter with cake 4.5.3
The idea is to create a pdf file and to send as attachment by email.
Cakepdf and Dompdf and the dokumentation “FriendsOfCake” is used for some years.
Until now I was used to write a pdf to the local download folder and handle further steps manually. How can I move the output to webroot-folder of the server?
Thanks for any tips!

So do you want to save the PDF file to webroot then send it using email?

Yes, that’s right. Do you have managed it?

I’ve only done HTML mailouts and PDF downloadable forms, but found this. Hope it helps

Mailer - 4.x (

maybe this one is your looking

use Cake\Mailer\Mailer;

$mailer = new Mailer(‘default’);
$mailer->setFrom([‘’ => ‘NewsLetter’])

‘sample.pdf’ => [
‘file’ => WWW_ROOT. ‘sample.pdf’,
‘mimetype’ => ‘application/pdf’,
‘contentId’ => uniqid()

dont forget to configure your smpt in app_local.php
‘EmailTransport’ => [
‘default’ => [
‘host’ => ‘’,
‘port’ => 587,
‘username’ => ‘’,
‘password’ => ‘’,
‘className’ => ‘Smtp’,
‘tls’ => true,
‘client’ => null,
‘url’ => env(‘EMAIL_TRANSPORT_DEFAULT_URL’, null),

I think you can adjust the configuration in CakePHP to specify the target directory within your webroot. Ensure that the folder permissions are set correctly to allow writing by the application.This approach maintains accessibility for web-based operations while integrating seamlessly with CakePDF and DomPDF for generating and sending email attachments.