我正在使用 symfony2 开发一个应用程序在应用程序的一侧,我正在发送电子邮件,一切正常。但是现在我创建了一个在 crontab 中运行的命令,但这不发送电子邮件。这是我的命令:使用 Doctrine\ORM\EntityManager;使用 Symfony\Component\Templating\EngineInterface;
类发件人{受保护的$ em;受保护的$twig;受保护的$mailer;公共函数 __construct($em, \Twig_Environment $twig, \Swift_Mailer $mailer) { $this->em = $em; $this->twig = $twig; $this->mailer = $mailer; }
public function runSender() {
$proj = $this->em->createQuery ...
$maillist = $this->em->createQuery ...
$templateFile = "projectprojBundle:MailList:emailNew.html.twig";
$templateContent = $this->twig->loadTemplate($templateFile);
$body = $templateContent->render(array('proj' => $proj));
foreach ($maillist as $m) {
$message = \Swift_Message::newInstance()->setSubject('New projects')
->setFrom('...')->setTo($m['email'])
->setContentType('text/html')
->setBody(trim($body));
$this->mailer->send($message);
} } }
查询一切正常,我测试过。如果我可以从其他班级发送,为什么我不能在这里?