【问题标题】:Additional mailer service to use the spool and send instant emails in Symfony2 - strange headers在 Symfony2 中使用假脱机和发送即时电子邮件的附加邮件服务 - 奇怪的标题
【发布时间】:2012-09-07 16:27:01
【问题描述】:

默认情况下,我使用假脱机邮件解决方案在我的网页中发送时事通讯。但我也需要立即发送电子邮件。所以我用了this solution

如果我使用 Spool 发送时事通讯,一切都很好。但是当我使用

$mailer = $this->get('instant_mailer');

我收到的电子邮件在开头添加了一些文字:

HTTP/1.0 200 OK Cache-Control: no-cache Content-Type: text/html; charset=UTF-8 日期:格林威治标准时间 2012 年 9 月 7 日星期五 16:19:06

如何去除?

【问题讨论】:

    标签: symfony swiftmailer spool


    【解决方案1】:

    我打赌你正在尝试发送一个响应对象。

    new Response();
    

    转到__toString()

    public function __toString()
    {
        $this->prepare();
    
        return
            sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
            $this->headers."\r\n".
            $this->getContent();
    }
    

    因为:

    $this->render('template.html.twig');
    

    返回 Response 以避免这种使用:

    $response = $this->render('template.html.twig');
    $text = $response->getContent();
    

    问候, 最大

    【讨论】:

    • 如果你赌上百万虫子,你就会成为百万富翁。谢谢你:)
    【解决方案2】:

    使用

    $content = $this->renderView('template.html.twig');
    

    而不是

    $content = $this->render('template.html.twig');
    

    render 返回响应

    【讨论】:

      【解决方案3】:

      该问题的其他可能解决方案是使用templating 服务而不是$this->render()

      <?php
      $body = $this->get('templating')->render('template.html.twig');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-04-13
        • 2017-08-05
        • 1970-01-01
        • 2014-02-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多