电子邮件不会发送给用户

时间:2013-07-31 20:26:56

标签: email symfony

发送带有raport的电子邮件时遇到问题。我创建了一些数据,然后尝试将其作为电子邮件发送给用户。但是电子邮件没有得到解决。我正在使用Symfony cookbool中配置的swiftmailer。 swiftmailer的参数设置正确,因为来自FosUserBundle的电子邮件正常运行。我已经写了一个方法在命令行中使用它,代码在

下面
class DailyRaportCommand extends ContainerAwareCommand
{
protected function configure()
{
    $this
        ->setName('raport:daily')
        ->setDescription('Send daily raports to the Users');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
    $em = $this->getContainer()->get('doctrine')->getEntityManager();
    $users = $em->getRepository('GLUserBundle:User')->findAllByRaport('DAILY');

    foreach($users as $user)
    {
        $date_to = new \DateTime();
        $date_to = $date_to->sub(date_interval_create_from_date_string('1 day'));
        $date_from = new \DateTime();
        $date_from = $date_from->sub(date_interval_create_from_date_string('1 day'));
        $format = "Y-m-d";

        $raport = array();

        foreach($user->getShops() as $shop)
        {
            $raport[$shop->getName()] = array();

            $shop_list = array();               
            $shop_list[] = $shop->getId();
            $groupBy = array();
            $all_policies = $em->getRepository('GLPolicyBundle:Policy')
                        ->findAllByOptions($shop_list, $date_from, $date_to, $groupBy);
            $raport[$shop->getName()]['all'] = $all_policies;

            $groupBy[] = 'typePolicy';
            $policies_by_type = $em->getRepository('GLPolicyBundle:Policy')
                        ->findAllByOptions($shop_list, $date_from, $date_to, $groupBy);
            $raport[$shop->getName()]['type'] = $policies_by_type;          

            $groupBy[] = 'bundle';
            $policies_by_bundle = $em->getRepository('GLPolicyBundle:Policy')
                        ->findAllByOptions($shop_list, $date_from, $date_to, $groupBy);
            $raport[$shop->getName()]['bundle'] = $policies_by_bundle;

        }

        $message = \Swift_Message::newInstance()
                ->setSubject('Dzienny raport sprzedaży')
                ->setFrom('g#######1@gmail.com')
                ->setTo($user->getEmail())
                ->setBody(
                    $this->getContainer()->get('templating')->render(
                        'GLRaportBundle:Raport:raport.html.twig',
                        array('raport' => $raport)
                    ));
        $this->getContainer()->get('mailer')->send($message);
}

电子邮件的wiev在外部文件中呈现。如果有人指出这个问题的原因,我将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可能需要手动刷新内存假脱机,请参阅以下答案,这有助于我解决同样的问题:

Unable to send e-mail from within custom Symfony2 command but can from elsewhere in app