我想发送一个带有变量名称的电子邮件。我创建了动作如下:想要在symfony 2中发送一封电子邮件,内容是变量
$product = $this->getDoctrine()
->getRepository('EnsNewBundle:Products')
->find(2);
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('[email protected]')
->setTo('[email protected]')
->setContentType("text/html")
->setBody($this->renderView('EnsNewBundle:Default:index.html.twig'));
$this->get('mailer')->send($message);
return $this->render('EnsNewBundle:Default:index.html.twig',array('name'=>$product->getName()));
在这里,我想$product->getName()
与邮件传输数据。在index.html.twig
我已经定义如下:
Id of the product 5<br/>
Name of the product {{name}} <br/>
Description Fast Internet browsing speed
当我执行这个动作,然后我收到错误undefined variable name in index.html.twig
。我应该怎么做,如果我想在发送邮件之前设置此值。 如果我为邮件正文制作硬编码,那么就没有问题了。