Additional mailer service to use the spool and send instant emails in Symfony2 - strange headers
Asked Answered
D

3

5

by default I use spool mailing solution for sending newsletter in my web page. But I also need to send email immediately. So I have used this solution

If I send newsletter with Spool everything is fine. But when I use

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

I receive email with some text prepend at the beginning:

HTTP/1.0 200 OK Cache-Control: no-cache Content-Type: text/html; charset=UTF-8 Date: Fri, 07 Sep 2012 16:19:06 GMT

How to remove this?

Decury answered 7/9, 2012 at 16:27 Comment(0)
A
7

I bet that you're trying to send a Response object.

new Response();

it goes to __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();
}

It is because:

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

returns Response to avoid that use:

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

Regards, Max

Arias answered 9/9, 2012 at 12:50 Comment(1)
If you would bet on it milion bugs, you would be a milioner. Thank you :)Decury
D
1

Use

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

instead of

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

render returns a response

Denysedenzil answered 10/1, 2014 at 9:37 Comment(0)
R
0

Other posible solution to the problem is to use templating service instead of $this->render():

<?php
$body = $this->get('templating')->render('template.html.twig');
Rok answered 21/11, 2013 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.