Question

I have a Symfony2 command where I am sending some emails. Everything works fine except the fact that the email is sent as from the dev environement which uses the delivery_address by default.

Here is how it works:

  1. Call the command class from the /etc/crontab
  2. The class will create the email and send it

    $message = \Swift_Message::newInstance()
        ->setContentType("text/html")
        ->setSubject('Daily Digest of Comments, '.$runningConference['name_full'])
        ->setFrom('conferences@mdpi.com')
        ->setTo('email1@test.com')
        ->addBcc('email2@test.com');
    
    $message->setBody($this->getContainer()->get('templating')->render('ProjectMyBundle:Page:paperCommentsDailyDigestEmailForSubscribers.txt.twig'));
    
    $this->getApplication()->getKernel()->getContainer()->get('mailer')->send($message);
    
  3. Each minute, I am senting the email from files with a cronjob.

    * * * * *      www-data php /var/www/myproject/app/console swiftmailer:spool:send --env=prod
    
Was it helpful?

Solution

I managed to find the problem. For the people in the same situation, you have to call your command with

--env=prod 

because by default the environment is dev.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top