Sunil Rawat
Sunil Rawat

Reputation: 709

Email Template goes as Raw Html using Swiftmailer Symfony2

Hi I am sending email templates to email as followas:

//here $emailBody is a twig template with html.

$mailBody = $this->templating->render('test/template/layout.html.twig', array(
              'mailBody' => $mailBody
));

$tmp = $this->mailer->createMessage();       
$tmp->setSubject(trim($emailSubject));
$tmp->setFrom('[email protected]');
$tmp->setTo($somnerecipeient);
$tmp->setBody($emailBody, 'text/html'); 
$sent = $this->mailer->send($tmp);

So when I am geting email my inbox its comes like raw html.Even content-type is already set text/html as:

$tmp->setBody($emailBody, 'text/html'); 

What could be the issue, Please assist

Thanks advance

Upvotes: 0

Views: 577

Answers (1)

Alvin Bunk
Alvin Bunk

Reputation: 7764

You should be using renderView and you spelled the content as $mailBody instead of $emailBody. So change like so:

$emailBody = $this->templating->renderView('test/template/layout.html.twig', array(
          'mailBody' => $mailBody
));

Can you try that and see if it resolves the issue.

Upvotes: 1

Related Questions