Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 217
Tom Avatar asked Sep 07 '12 16:09

Tom


2 Answers

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

like image 100
Max Małecki Avatar answered Nov 08 '22 12:11

Max Małecki


Use

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

instead of

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

render returns a response

like image 29
jalso Avatar answered Nov 08 '22 12:11

jalso