symfony2不发送电子邮件

时间:2013-11-12 08:44:10

标签: symfony mailer

我正在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

但由于某种原因,这不发送电子邮件。我做错了什么?

1 个答案:

答案 0 :(得分:1)

By default封电子邮件存储在文件中,您需要运行以下命令发送它们:

console swiftmailer:spool:send

如果您想直接发送电子邮件而不进行假脱机,请将spool: { type: memory }添加到您的配置文件中:

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

更多详细信息,请参阅Symfony2 documentation