首页 > 解决方案 > Symfony 4 + Swift Mailer - 从 127.0.0.1 发送电子邮件时出错

问题描述

Symfony 4 应用程序使用 Swift Mailer 发送电子邮件。

我已经编写了我的控制器逻辑并创建了一个表单,电子邮件都在生产服务器上工作。

但是在开发模式下运行时php bin/console server:run出现错误:

Service "logger" not found: even though it exists in the app's container, the container inside "App\Controller\PageController" is a smaller service locator that only knows about the "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services.

Try using dependency injection instead.

我只是按原样使用捆绑包。为什么我不能从本地开发环境发送电子邮件?

标签: phpsymfonyswiftmailer

解决方案


您以某种方式替换了 Symfony 内部的默认容器App\Controller\PageController。此消息基本上意味着对象未在容器中设置其依赖项。详情请看这里:https ://symfony.com/doc/current/service_container.html

Symfony 使用容器模式,它将许多对象保存在一个容器中,可以通过整个应用程序访问。


推荐阅读