In cakephp3 I'm using debugkit. My goal is to create a new Mailer transport class which stores the outgoing emails in a database in order to prevent it to sent out when in debug mode.
I've placed my Transport class in
src/Mailer/Transport/DbMailTransport.php
Followed this I've set this class as default Mailer transport.
Email::configTransport('default', [
'className' => 'DbMail',
'host' => '',
'port' => false,
'timeout' => false,
'username' => '',
'password' => '',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
]);
When trying to send an email I got the following error:
Fatal error: Cannot declare class Cake\Mailer\Transport\DbMailTransport, because the name is already in use in /src/Mailer/Transport/DbMailTransport.php on line 0
After further digging in the code debugging the $_transportConfig I got the following variables:
array(1) {
["default"]=>
array(11) {
["className"]=>
string(17) "DebugKit.DebugKit"
["host"]=>
string(0) ""
["port"]=>
bool(false)
["timeout"]=>
bool(false)
["username"]=>
string(0) ""
["password"]=>
string(0) ""
["client"]=>
NULL
["tls"]=>
bool(true)
["url"]=>
NULL
["originalClassName"]=>
string(6) "DbMail"
["debugKitLog"]=>
object(ArrayObject)#184 (1) {
["storage":"ArrayObject":private]=>
array(0) {
}
}
}
}
So the className is "DebugKit.DebugKit" instead of "DbMail". After turning off DebugKit in the bootstrap.php I got the correct classname:
array(1) {
["default"]=>
array(9) {
["className"]=>
string(6) "DbMail"
["host"]=>
string(0) ""
["port"]=>
bool(false)
["timeout"]=>
bool(false)
["username"]=>
string(0) ""
["password"]=>
string(0) ""
["client"]=>
NULL
["tls"]=>
bool(true)
["url"]=>
NULL
}
}
My transport class working as expected, saves the outgoing emails to the database, so clearly the debugkit causing problems. Any idea how to resolve the issue?