'CakePHP 4.x MissingTemplate Exception when EmailTransport url is defined

Inside app_local.php:

    'EmailTransport' => [
        'default' => [
            'className' => MailTransport::class,
            /*
             * The keys host, port, timeout, username, password, client and tls
             * are used in SMTP transports
             */
            'host' => 'localhost',
            'port' => 25,
            'timeout' => 30,
            /*
             * It is recommended to set these options through your environment or app_local.php
             */
            //'username' => null,
            //'password' => null,
            'client' => null,
            'tls' => false,
            'url' => 'myCompany-org.mail.protection.outlook.com'
        ],
    ],

Currently, when I set the url property to a string, the app crashes with the error below: If the value of url is null then the application does not crash.

Fatal error: Type of Cake\View\Exception\MissingTemplateException::$file must be string (as in class Exception) in C:\xampp\htdocs\creative_trak_2\vendor\cakephp\cakephp\src\View\Exception\MissingTemplateException.php on line 23

I thought this could have been a routing issue but I don't know any routes that MailTransport uses. Since I am using React Router, my app is a single page app and my routes.php file looks like:

$routes->scope('/', function (RouteBuilder $builder) {
  
    // Single Page Application
    $builder->connect('/*', ['controller' => 'Pages', 'action' => 'main']);
    $builder->connect('/users/{action}', ['controller' => 'Users']);
    $builder->connect('/pages/*', 'Pages::display');
    $builder->fallbacks();
});

I checked my logs and there was not no error appearing. Any advice is appreciate on how to further debug this.

Thank you.



Solution 1:[1]

The error message that you're seeing is because you're using a version of CakePHP that is not compatible with your PHP version (https://github.com/cakephp/cakephp/pull/15529). Upgrade to the latest 4.x to see the actual error.

That being said, that's not a valid DSN string, which is what the url option is meant to be used with. A valid DSN string consists of at least a schema and a host, like:

smtp://smtp.example.com

For your external host you'd most likely need more details of course, username password, etc..., a more complete example would be:

smtp://user:[email protected]:587?tls=true

Not that you'd need to use a DSN string here if you want to hardcode things. Anyhow, first figure the details that you need to connect to outlook, and then go from there.

See also https://book.cakephp.org/4/en/core-libraries/email.html#configuring-transports

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ndm