我正在開發一個應用程序與symfony2 在應用程序的一邊我發送電子郵件,一切正常與此。 但現在我創建一個命令在crontab中運行,但不發送電子郵件。 這是我的命令: 使用Doctrine \ ORM \ EntityManager; 使用Symfony \ Component \ Templating \ EngineInterface;symfony2電子郵件沒有發送命令
class Sender { protected $ em;受保護的$ twig;受保護的$郵件程序; public function __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);
} } }
一切都確定了查詢,我測試。 如果我可以從其他班級發送爲什麼我不能在這裏?在config.yml
使用spool: { type: memory }
您使用假脫機內存嗎?如果是,這是問題。 見http://stackoverflow.com/questions/13122096/unable-to-send-e-mail-from-within-custom-symfony2-command-but-can-from-elsewhere –
是使用im閥芯內存。它可以在其他類中使用。但在這裏它不工作,我不知道爲什麼你 – BrunoRamalho
可以澄清它可以在其他類CLI或當你在網絡工作。這是一個重點。檢查我發佈的鏈接。 –