我想发送一封带有变量名的电子邮件。我创建了如下操作:
$product = $this->getDoctrine()
->getRepository('EnsNewBundle:Products')
->find(2);
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('ucerturohit@gmail.com')
->setTo('ucerturohit@gmail.com')
->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
。如果我想在发送邮件之前设置此值,我该怎么办。如果我为电子邮件正文制作硬代码,那么就没有问题。