【问题标题】:Send Emails with CakePHP 4使用 CakePHP 4 发送电子邮件
【发布时间】:2021-03-02 15:44:26
【问题描述】:

我想用 CakePHP 4 发送电子邮件。 在 app_local.php 我有以下条目

    'EmailTransport' => [
    'default' => [
        'host' => 'smtp.XXX.de',
        'port' => 25,
        'username' => null,
        'password' => null,
        'client' => null,
        'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
    ],
],

如果我尝试使用以下代码发送电子邮件

            $mailer = new Mailer('default');
            $mailer->setFrom(['willi@test.de' => 'Willi'])
                ->setTo('wutz@test.de')
                ->setSubject('About')
                ->deliver('blablabla');

我收到以下错误消息

Could not send email: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

为什么 Cake 试图在本地主机上使用 Mailserver ??? 我的错误在哪里? ;-)

【问题讨论】:

  • 您的邮件服务器在当今时代使用端口 25 和无密码访问是相当奇怪的。
  • 这是一个内部测试系统,仅用于检查是否有任何工作...
  • 您在该文件中是否还有一个Email 部分,与EmailTransport 分开?
  • @Greg Schmidt 是的,电子邮件部分在这里...'Email' => [ 'default' => [ 'transport' => 'default', 'from' => 'you@localhost', /* * Will by default be set to config value of App.encoding, if that exists otherwise to UTF-8. */ //'charset' => 'utf-8', //'headerCharset' => 'utf-8', ], ],
  • 我终于找到了它......我使用蛋糕应用程序骨架,我认为电子邮件传输的配置不像蛋糕 4 那样......在配置中你必须告诉类名应该如何传输邮件.... mail / smtp / debug 在 app_local 我现在添加了'EmailTransport' => [ 'default' => [ 'className' => 'Smtp',

标签: php cakephp-4.x


【解决方案1】:

你错过了:'className' => 'Smtp'。

'EmailTransport' => [
    'default' => [
 'className' => 'Smtp',
        'host' => 'smtp.XXX.de',
        'port' => 25,
        'username' => null,
        'password' => null,
        'client' => null,
        'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
    ],
],

【讨论】:

  • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
猜你喜欢
  • 2014-01-17
  • 2014-02-12
  • 1970-01-01
  • 2011-11-12
  • 2018-01-07
  • 2019-12-02
  • 1970-01-01
  • 2012-05-11
  • 1970-01-01
相关资源
最近更新 更多