System of scheduling of emails

Asked

Viewed 68 times

0

I have the following problem:

A user performs a step of an X test, when he clicks to get the first result I need to create 9 e-mail messages to be sent to the 3-day logo, morning (7:00), afternoon (13:00) and night (21:00). The question is how can I define the 3 times? The dates I already got.

My schedule 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;
  • In short, it could be more specific, what is the real problem ? You implemented some code, if yes, post it.

  • What is the difficulty? Implementation or logic? If they are fixed times, only make one for on days and insert in 3 times.

  • There’s no better way than using one for within another?

1 answer

1


In 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);

    }

}
  • Well, that’s it... in my view it’s the best way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.