我想发送和发送电子邮件:
$message = \Swift_Message::newInstance()
->setSubject('bla bla')
->setFrom('example@gmail.com')
->setTo('example@gmail.com')
->setCharset('UTF-8')
->setContentType('text/html')
->setBody("hi");
$this->getContainer()->get('mailer')->send($message);
$output->writeln('sent!');
但是,我想附加一个这样的生成模板:
$template = $this->getContainer()->get('templating');
$xml = $template->render("MrLibrariesReportsBundle:Transactions:download.xml.twig", $viewData);
我试着这样做:
$message->attach($xml);
但它不起作用。
我该怎么办?
谢谢!
答案 0 :(得分:0)
这样的事情:
$message = \Swift_Message::newInstance()
->setSubject('Subject')
->setFrom('From')
->setTo('To')
->setBody($this->container->get('templating')->render(
'AppBundle:Mail:welcome.html.twig', $viewData),
'text/html'
);
$this->container->get('mailer')->send($message);
答案 1 :(得分:0)
我解决了。我做了下一个代码:
$message = \Swift_Message::newInstance()
->setSubject('bla bla')
->setFrom('example@gmail.com')
->setTo('example@gmail.com')
->setCharset('UTF-8')
->setContentType('text/html')
->setBody("hi")
->attach(\Swift_Attachment::fromPath($attach));
$this->getContainer()->get('mailer')->send($message);
$output->writeln('sent!');
$ attach是文件的补丁,或者在这种情况下是模板的渲染:
$template = $this->getContainer()->get('templating');
$xml = $template->render("MrLibrariesReportsBundle:Transactions:download.xml.twig", $viewData);
$ attach == $ xml
最重要的是:
\ Swift_Attachment ::