This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Can't Get Email to Send Out By Task/Cron

Discussion relating to version 1.3.x and 1.4.x

Can't Get Email to Send Out By Task/Cron

by jeremyrperry » Wed Jul 23, 2014 9:04 pm

I am working with Symfony 1.4 and was able to create a task for sending off an email with a CSV attachment. When I run the task from the command line, it is able to pull in the correct data from the related module without issue, but the email won't send out. Here is the code from the task I built:

Code: Select all

class reportsTask extends sfBaseTask
  protected function configure()
    // // add your own arguments here
    // $this->addArguments(array(
    //   new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),
    // ));
   require_once sfConfig::get('sf_root_dir').'/apps/dashboard/modules/reports/actions/actions.class.php';
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
      new sfCommandOption('type', null, sfCommandOption::PARAMETER_OPTIONAL, 'The output type of the report', 'email')
      // add your own options here

    $this->namespace        = '';
    $this->name             = 'reports';
    $this->briefDescription = '';
    $this->detailedDescription = <<<EOF
The [reports|INFO] task does things.
Call it with:

  [php symfony reports|INFO]

  protected function execute($arguments = array(), $options = array())
    $databaseManager = new sfDatabaseManager($this->configuration);
    $output = reportsActions::buildReport($options['type']);
        case 'csv':
            echo $output;
        case 'email':
            $message = $this->getMailer()->compose($output['from'], $output['to'], $output['subject']);
            $message->setBody($output['body']['content'], $output['body']['type']);
            $message->attach(Swift_Attachment::newInstance($output['attachment']['content'], $output['attachment']['name'], $output['attachment']['type']));
            $this->getMailer()->sendNextImmediately()->send($message) or die('email failed to deliver');
            $output = array('status'=>'success', 'to'=>$output['to']);
            echo json_encode($output);

I referenced the official Symfony documentation when building my task and tried using examples from other sites I found from a Google search, but nothing seemed to help. Greatly appreciated if anybody has knowledge on this and can point me in the right direction.
Junior Member
Posts: 1
Joined: Wed Jul 23, 2014 8:48 pm

Re: Can't Get Email to Send Out By Task/Cron

by KriZa » Thu Aug 21, 2014 1:25 pm

What is your development environment? localhost or a real server?
Junior Member
Posts: 2
Joined: Thu Aug 14, 2014 10:36 am