I hope you're all doing well.
I'm having some difficulties passing variables to an email template in CakePHP 4.x. I have looked through the documentation and tried a few different things, but I can't seem to get it to work.
Here's what I'm trying to achieve: I want to send an email to a user and include some dynamic data in the email body. For example, I want to include the user's name, username, and email address in the email.
I have already set up the email configuration in my `app.php` file, and I can successfully send emails using the default template. But I can't figure out how to pass variables to the email template and use them in the email body.
I have tried following the instructions in the CakePHP documentation, specifically the section on "Sending email with view templates". I have created a custom email template in the `src/Template/Email/html` folder, and I have tried passing variables to the template using the `set()` method, but it doesn't seem to work.
Here's an example of what I have tried in my controller:
$email = new Email('default');
->setViewVars(['name' => 'John Doe', 'username' => 'johndoe', 'email' => 'email@example.com'])
And in my custom email template (`src/Template/Email/html/welcome.ctp`), I have tried accessing the variables using `$name`, `$username`, and `$email`, but it doesn't seem to work. The variables are always empty.
I have also tried passing variables using the `viewBuilder()` method in the `build()` function of my email template, like this:
$this->viewBuilder()->setVars(['name' => 'John Doe', 'username' => 'johndoe', 'email' => 'firstname.lastname@example.org']);
But that didn't work either.
Am I missing something here? Is there a different way to pass variables to email templates in CakePHP 4.x? Any help would be greatly appreciated.
Thank you in advance.