I am having troubles with the Mailer after upgrading from CakePHP 3 to 4. This is the relevant part my configuration:
<?php
return [
'EmailTransport' => [
'default' => [
'className' => 'Mail',
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'password',
'client' => null,
'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
'cronjob' => [
'className' => 'Mail',
],
'accounts' => [
'className' => 'Mail',
],
],
'Email' => [
'default' => [
'transport' => 'default',
'from' => 'you@localhost',
],
'cronjob' => [
'transport' => 'cronjob',
'from' => 'cronjob@foobar.com',
],
'accounts' => [
'transport' => 'accounts',
'from' => 'accounts@foobar.com',
],
],
];
This is the snippet that's causing the error:
private function sendActivationEmail(User $user)
{
$url = Router::url([
'prefix' => 'Admin',
'plugin' => 'UserManager',
'controller' => 'Users',
'action' => 'activate',
$user->username,
$user->activation_key,
], true);
debug(Configure::read('EmailTransport'));
debug(Configure::read('Email'));
$mailer = new Mailer('accounts');
$mailer->setFrom(['accounts@foobar.com' => 'Foobar Website Manager'])
->setTo($user->email, $user->fullName)
->setSubject('Please activate your account')
->setEmailFormat('html')
->setViewVars(compact('url', 'user'))
->viewBuilder()
->setTemplate('UserManager.register');
return $mailer->deliver();
}
The error is Unknown email configuration "accounts".
, thrown in
The output of the two debug
functions is the following:
/vendor/plugins/usermanager/src/Model/Table/UsersTable.php (line 72)
[
'default' => [
'className' => 'Mail'
],
'cronjob' => [
'className' => 'Mail'
],
'accounts' => [
'className' => 'Mail'
]
]
/vendor/plugins/usermanager/src/Model/Table/UsersTable.php (line 73)
[
'default' => [
'transport' => 'default',
'from' => 'something@foobar.com'
],
'cronjob' => [
'transport' => 'cronjob',
'from' => 'cronjob@foobar.com'
],
'accounts' => [
'transport' => 'accounts',
'from' => 'accounts@foobar.com'
]
]
So it seems like the accounts
key is present in the mail configuration, then why am I getting this error?