Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftmailerBundle how can send email with html content? Symfony 2

i try to send template with html content but in email i received only text

how can i set for send email with html content?

$messaggio = \Swift_Message::newInstance()
                ->setSubject('Hello Email')
                ->setFrom('[email protected]')
                ->setTo('[email protected]')
                ->setBody($this->renderView('AcmeUserBundle:Default:email.text.twig'))
                ;
                $this->get('mailer')->send($messaggio);
like image 869
Popolitus Avatar asked Feb 04 '12 19:02

Popolitus


2 Answers

Specify content-type using ->setContentType("text/html")

like image 65
Anton Babenko Avatar answered Nov 05 '22 23:11

Anton Babenko


You have to specify 'text/html' type:

->setBody($this->renderView('...:....html.twig'), 'text/html')
like image 13
Wojciech Jasiński Avatar answered Nov 06 '22 00:11

Wojciech Jasiński