E-mail Scheduling System

0

I have the following problem:

A user performs a test X step, when he clicks to get the first result, he must create 9 e-mail messages to be sent to the logo of 3 days, morning (7:00), afternoon (13: 00) and the night (21:00). The question is how can I set the 3 schedules? Dates have already been achieved.

My scheduling table has the following structure:

CREATE TABLE maas_emails_agendados (
  email_id int(11) NOT NULL auto_increment,
  email_destinatario_nome varchar(255) default NULL,
  email_destinatario varchar(255) default NULL,
  email_assunto varchar(255) default NULL,
  email_mensagem text,
  email_agendamento datetime default NULL,
  cliente_id int(11) default NULL,
  PRIMARY KEY  (email_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
asked by anonymous 31.05.2017 / 20:25

1 answer

1

At the end, there was some suggestion of how to simplify?

$dias = 3;

$horarios = array(
    'Manhã'=>'7:00:00',
    'Tarde'=>'13:00:00',
    'Noite'=>'21:00:00'
);

for ($i=1; $i <= $dias; $i++) { 

   foreach ($horarios as $key => $value) {

       $email_destinatario = $cliente_email;

       $email_assunto = SISTEMA_NAME.': Autodiagnóstico '.$key.' - Dia #'.$i;

       $email_mensagem = $functions->get_emails_tags($dados_email['email_corpo'],$cliente_id);

       $data = date('Y-m-d '.$value);

       $email_agendamento = date('Y-m-d H:i:s', strtotime("+".$i." days",strtotime($data)));

       $dados_emails = array(
           'email_destinatario_nome'=>$cliente_nome,
           'email_destinatario'=>$email_destinatario,
           'email_assunto'=>$email_assunto,
           'email_mensagem'=>$email_mensagem,
           'email_agendamento'=>$email_agendamento,
           'cliente_id'=>$cliente_id
       );

       $conecta->inserir('maas_emails_agendados',$dados_emails);

    }

}
    
31.05.2017 / 21:15