Php Symfony 3和Mailhog:邮件未被Mailhog缓存
在我的开发环境中,我想使用mailhog来捕获电子邮件。我已经安装并配置了php.ini以替代sendmail属性。 如果在命令行中,我运行这个Php Symfony 3和Mailhog:邮件未被Mailhog缓存,php,symfony,email,development-environment,Php,Symfony,Email,Development Environment,在我的开发环境中,我想使用mailhog来捕获电子邮件。我已经安装并配置了php.ini以替代sendmail属性。 如果在命令行中,我运行这个 php -r "mail(......);" 邮件被mailhog捕获。问题在于Symfony和Swiftmailer。为了进行测试,我使用以下方法创建了一个非常简单的控制器: /** * @return Response */ public function homeAction() : Response {
php -r "mail(......);"
邮件被mailhog捕获。问题在于Symfony和Swiftmailer。为了进行测试,我使用以下方法创建了一个非常简单的控制器:
/**
* @return Response
*/
public function homeAction() : Response
{
mail('some@mail.com', 'tasest', 'aaaa');
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('send@example.com')
->setTo('recipient@example.com')
->setBody(
'aaaaa',
'text/html'
);
$this->get('mailer')->send($message);
return $this->render('::base.html.twig');
}
现在,邮件功能发送的电子邮件被mailhog捕获。但不是SwiftMailer发送的邮件
在我的配置文件中,我有:
# Swiftmailer Configuration
swiftmailer:
transport: "sendmail"
我认为这应该足够了
我是不是遗漏了什么
注:如果我使用真实地址(而不是recipient@example.com)电子邮件被发送和接收
更新:
我还尝试为smtp配置mailhog,parameters.yml:
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_port: 1025
mailer_user: null
mailer_password: null
config.yml:
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
port: "%mailer_port%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
但是结果是相同的。Symfony中的Swiftmailer设置通常会有一个更完整的配置,特别是在config_dev.yml中,以明确您将发送到哪里
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
port: "%mailer_port%"
username: "%mailer_user%"
password: "%mailer_password%"
在这里,如果Mailhog位于端口1025上(非常典型),那么开发环境中的parameters.yml将如下设置,以填充.yml文件中的参数:
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_port: 1025
mailer_user: null
mailer_password: null
我对Symfony 4有同样的问题。
如果删除
config/packages/swiftmailer.yaml
中的变量url:“%env(MAILER\u url)%”
,它应该可以工作。问题已解决,缓存有问题您能详细解释缓存有什么问题吗?我面临同样的问题,刷新缓存似乎无法解决我的问题。在我的情况下,这不起作用。我需要保留env MAILER_URL并将其添加到.env
文件中<代码>邮件地址=smtp://127.0.0.1:1025