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条)

报告相同问题?

悬赏问题

  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA