What I have
In my Controller (CakePHP 3.8):
$email = new \Cake\Mailer\Email();
$email
->emailFormat('html')
->setLayout('mylayout')
->setTo($to)
->setSubject($subject)
->addAttachments([
'logo.png' => [
'file' => $logoImage,
'mimetype' => mime_content_type($logoImage),
'contentId' => 'mylogo'
]
])
->send($message);
And then in src/Template/Layout/Email/html/mylayout.ctp
:
<img src="cid:mylogo">
That works.
What I want
I want to embed that image from within the Layout file.
- So I don't have to repeat
->addAttachments()
every time I'm sending an e-mail - If I replace the image I can do it in the Layout only once
- If I use another Layout that doesn't need the image, it won't be attached and sent
Using contentId
looks like an option. But how do I do it from inside the Layout?
What I tried
- Sending the image as data/uri, but that didn't work
- Searching for some
Cake\Mailer
instance under$this
when in Layout, but couldn't find any