AnsweredAssumed Answered

How can i user sugar email system on php jobs?

Question asked by Giovanni Marazzi on Feb 6, 2018
Latest reply on Feb 8, 2018 by Giovanni Marazzi

I am creating a scheduler job that needs to send e-mails to users and contacts and create tasks to users. How can i do that via php code? I think i have a idea of how to create tasks through new Bean but i don't have a clue on how to send e-mails from sugar.

Here is what i got so far:

function lftm_it_data_ativacao_job() {
    
    
     $sql = "SELECT T0.id, T1.lftm_it_acima_max_c, T1.lftm_tipo_atendimento_c, T1.lftm_carteira_adm_c T1.lftm_dias_saldo_positivo_c, ";
     $sql .= "T0.email FROM contacts T0 ";
     $sql .= "INNER JOIN contacts_cstm T1 ON T0.id = T1.id_c ";
     $sql .= "WHERE T1.lftm_it_acima_min_c = 1;";
    
    
     $GLOBALS['log']->fatal('Start positive cash job');
     $cnt = 0;
     $conn = $GLOBALS['db']->getConnection();
    
     $GLOBALS['log']->fatal('Got Connection');
    
     $stmt = $conn->executeQuery($sql);
    
     $GLOBALS['log']->fatal('Query executed');
    
     while($row = $stmt->fetch()) {    
    
         
          if($row['lftm_carteira_adm_c'] = 1) {
              
          } else {
               if($row['lftm_tipo_atendimento_c'] = 'SelfService') {
                    if($row['lftm_dias_saldo_positivo_c'] == 3) {
                         //send email to client
                    }
                    if($row['lftm_dias_saldo_positivo_c'] >= 10) {
                         //create task to advisor
                    }
               }
               if($row['lftm_tipo_atendimento_c'] = 'Regular' || $row['lftm_tipo_atendimento_c'] = 'FullService') {
                    if($row['lftm_it_acima_max_c'] != 0) {
                         if($row['lftm_dias_saldo_positivo_c'] == 1) {
                              //send email to advisor and client informing the need to allocate cash
                         }
                         if($row['lftm_dias_saldo_positivo_c'] == 4) {
                              //create task to officer to reach advisor
                         }
                         if($row['lftm_dias_saldo_positivo_c'] >= 10) {
                              //send email to advisor and superior informing that cash didn't change
                         }    
                    } else {
                         if($row['lftm_dias_saldo_positivo_c'] == 1) {
                              //send email to officer and client with order to allocate cash
                         }
                         if($row['lftm_dias_saldo_positivo_c'] == 3) {
                              //create task to officer to reach client
                         }
                         if($row['lftm_dias_saldo_positivo_c'] >= 10) {
                              //create task to advisor informing that officer didn't get response
                         }    
                    }
               }
          }
          $cnt++;
          $GLOBALS['log']->fatal(''. $cnt .' Registers Saved');
     }
    
     $GLOBALS['log']->fatal('All Registers Saved');
    return true;

}

Outcomes