1

我正在 Symfony2 中开发应用程序 我有一个将在 crontab 中运行的命令

这是命令:

<?php
namespace project\projBundle\Service;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Templating\EngineInterface;
class Sender {
    protected $em;
    protected $templating;
    protected $mailer;
    public function __construct($em, $templating,\Swift_Mailer $mailer) {
        $this->em = $em;
        $this->templating = $templating;
        $this->mailer = $mailer; }

    public function runSender() {
        $proj = $this->em->createQuery("query")->setMaxResults(20)->getResult();
        $message = \Swift_Message::newInstance()
            ->setSubject('Contact enquiry from symblog')
            ->setFrom('...@gmail.com')
            ->setTo('...@gmail.com')
            ->setBody($this->templating->render('projectprojBundle:Others:emailNew.html.twig', array('proj' => $proj)));

        $this->mailer->send($message); } }

参数.yml:

parameters:
    mailer_transport: gmail
    mailer_host: ~
    mailer_user: ...@gmail.com
    mailer_password: ...

在 config_test 中:

swiftmailer:
disable_delivery: false
spool: { type: memory }

这是向我发送电子邮件,但我收到 2 封电子邮件:第 1 封:

Delivery to the following recipient failed permanently:

     ...@gmail

Technical details of permanent failure:
DNS Error: Domain name not found

在第二个树枝代码中,没有渲染。

我做错了什么?

4

2 回答 2

2

您是否在 config.yml 中添加了这个:

swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%
于 2013-11-12T11:22:15.527 回答
1

我用它修复树枝:

protected $twig;
    protected $mailer;
    public function __construct(\Twig_Environment $twig,\Swift_Mailer $mailer) {
        $this->twig = $twig;
        $this->mailer = $mailer;
    }

但现在的问题是我仍然有 html 标签。

于 2013-11-12T11:30:45.283 回答