I am having trouble redirecting after a certain function that sends emails! My function is:
public function emailAction($emails, $url)
{
foreach($emails as $email)
{
$message = \Swift_Message::newInstance()
->setSubject('Updates in Symfony Blog')
->setFrom(array('blog@symfonyblog.com' => 'Symfony Blog'))
->setTo($email["email"])
->setBody(
$this->renderView(
'NEWSBlogBundle:Default:email.txt.twig',
array('url' => $url)
)
)
;
$this->get('mailer')->send($message);
}
return $this->redirect($this->newpostAction());
//return $this->redirect($this->generateUrl('NEWSBlogBundle_homepage'));
}
It sends the emails OK, but then when redirecting, gives the error:
ErrorException: Warning: Header may not contain more than a single header, new line detected in C:\path\to\webroot\Symfony\app\cache\dev\classes.php line 3899
- in C:\path\to\webroot\Symfony\app\cache\dev\classes.php line 3899
- at ErrorHandler->handle('2', 'Header may not contain more than a single header, new line detected', 'C:\path\to\webroot\Symfony\app\cache\dev\classes.php', '3899', array('this' => object(RedirectResponse), 'name' => 'Location', 'values' => array('/app_dev.php/blog', object(ResponseHeaderBag), ' Redirecting to /app_dev.php/blog Redirecting to /app_dev.php/blog. ', '1.0', '302', 'Found', null), 'value' => object(ResponseHeaderBag)))
- at header('Location: Cache-Control: no-cache Date: Wed, 17 Jul 2013 11:56:17 GMT Location: /app_dev.php/blog ', false) in C:\path\to\webroot\Symfony\app\cache\dev\classes.php line 3899
- at Response->sendHeaders() in C:\path\to\webroot\Symfony\app\cache\dev\classes.php line 3914
- at Response->send() in C:\path\to\webroot\Symfony\web\app_dev.php line 27
while I haven't changed anything about any "headers" (and don't really know what it is about!). My app_dev.php is:
<?php
use Symfony\Component\HttpFoundation\Request;
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
I tried two different ways of redirecting both (through routing and directly calling the controller) of which give the same error, whilst the pages load if I jusr type in their url!
I have NO idea what this error is and how I should fix it!