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?

Community
  • 1
  • 1
Tom
  • 1,203
  • 3
  • 15
  • 35

3 Answers3

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

Max Małecki
  • 1,700
  • 2
  • 13
  • 18
1

Use

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

instead of

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

render returns a response

jalso
  • 78
  • 6
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');
m4t1t0
  • 5,669
  • 3
  • 22
  • 30