dongqigu0429 2017-03-16 16:54
浏览 42
已采纳

Symfony 3和Mailhog:邮件没有被mailhog缓存

In my dev enviroment I want to use mailhog to catch the emails. I've installed and configure my php.ini to sustitute the sendmail property. If in command line i run this

php -r "mail(......);" 

the mail gets captured by mailhog. The problem is with Symfony and Swiftmailer. To make a test i created a very simple controller with this:

/**
     * @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');
    }

Now, the email sent by the mail function gets captured by mailhog. But not the mail sent by SwiftMailer.

In my config_dev I have this:

    # Swiftmailer Configuration
swiftmailer:
    transport: "sendmail"

which I think should be enough.

Am I missing something here?

P.S.: If i use a real address (instead of recipient@example.com) the email gets sent and received

Update: I also tried to configure mailhog for smtp, 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 }

But the result was the same result.

  • 写回答

2条回答 默认 最新

  • drpfu51608120170 2017-03-16 19:12
    关注

    Swiftmailer setup in Symfony will usually have a more complete configuration, particularly in config_dev.yml, to be explicit of where you would send it.

    swiftmailer:
        transport: "%mailer_transport%"
        host:      "%mailer_host%"
        port:      "%mailer_port%"
        username:  "%mailer_user%"
        password:  "%mailer_password%"
    

    Here, if Mailhog was on port 1025 (very typical), then parameters.yml in a development environment would be set like this, to fill in the parameters in the .yml file:

    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_port: 1025
    mailer_user: null
    mailer_password: null
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在不同的执行界面调用同一个页面
  • ¥20 基于51单片机的数字频率计
  • ¥50 M3T长焦相机如何标定以及正射影像拼接问题
  • ¥15 keepalived的虚拟VIP地址 ping -s 发包测试,只能通过1472字节以下的数据包(相关搜索:静态路由)
  • ¥20 关于#stm32#的问题:STM32串口发送问题,偶校验(even),发送5A 41 FB 20.烧录程序后发现串口助手读到的是5A 41 7B A0
  • ¥15 C++map释放不掉
  • ¥15 Mabatis查询数据
  • ¥15 想知道lingo目标函数中求和公式上标是变量情况如何求解
  • ¥15 关于E22-400T22S的LORA模块的通信问题
  • ¥15 求用二阶有源低通滤波将3khz方波转为正弦波的电路