Mailer get body with layout

I need to get back the whole layout of the email template without sending an email, is it possible?

I use this to send an email:

$this->getMailer('Admin')->send('messageOrder', [$dataPost])

Thank You

Have you looked into the mail debugging features of the DebugKit?

No DebugKit, I want me in the variable of the whole layout, including the content from the email message.

What have you tried? I’m not experienced with the Mailer system but, looking around the class there are several suggestive bits.

For one, Mailer seems to use the normal ViewBuilder, layouts, and templates. This suggests to me that you can render your content outside of the Mailer system if you don’t actually want to email it.

Also, the Message class mentioned here has a getBody() method. That seems like another avenue for exploration. The example code there suggest you might be able to prepare your message then get it’s body without sending it.

Have you looked into either of these possibilities?

Thanks for the information, I looked at it, but unfortunately none of it works for me, or I just can’t do it.

The Cake\Mailer\Email class is the thing that renders the message. Unfortunately, the only call to the _render function in there is when you send, and the _render function itself is protected, so you can’t access it directly. My suggestion would be to make your own Email class, extending the core version, and just adding a function that calls _render and returns the results of that.

1 Like

Good idea, thank you!