cakephp 4.x丢失的板块异常定义了EmailTransport URL

发布于 2025-01-26 08:36:12 字数 1679 浏览 3 评论 0 原文

内部 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'
        ],
    ],

当前,当我将 url 属性设置为字符串时,应用程序崩溃了,以下错误: 如果 url 的值为null,则应用程序不会崩溃。

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

我认为这可能是一个路由问题,但我不知道MailTransport使用的任何路线。由于我使用的是React Router,因此我的应用是一个单页应用程序,我的 doutes.php 文件看起来像:

$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();
});

我检查了我的 logs ,并且没有出现错误。任何建议都感谢如何进一步调试此问题。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玻璃人 2025-02-02 08:36:12

您正在看到的错误消息是因为您使用的是与您的PHP版本不兼容的CakePHP( https://github.com/cakephp/cakephp/cakephp/pull/15529 )。升级到最新的4.x以查看实际错误。

话虽如此,这不是有效的DSN字符串,这是 url 选项的目的。有效的DSN字符串至少由架构和主机组成,例如:

smtp://smtp.example.com

对于您的外部主机,您很可能需要更多详细信息,用户名密码等...,一个更完整的示例是:

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

不是您' D如果您想进行硬码内容,则需要在此处使用DSN字符串。无论如何,首先要了解您需要连接到Outlook的详细信息,然后从那里开始。

另请参见

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文