SELECT user by Date

1

I have Select mysql that searches my clients for the name, email for the date of the day ...

I need to get the results that are today's (WHERE data_cad='$dataHoje') and I need to select one by one to send an email to it (I'll use mail () )

My main question is how to select ONE to ONE and do the One-to-One Sending .. I lacked the logic for this ...

Thank you!

    
asked by anonymous 20.12.2016 / 00:56

1 answer

1

Come on, as you did not specify the average amount of emails I'll create a simple example of how to do this:

I'm going to use PDO for queries, but you can do as you like

$select = BD::conn()->prepare("SELECT * FROM minhaTabela WHERE DATE(timestamp_field) = CURDATE()");
$select->execute();

$rows = $select->rowCount();

if($rows >= 1){
   while($ftc = $select->fetch()){
      $para = $ftc["email"];
      $assunto = "Assunto do email";
      $msg = "Sua mensagem aqui";
      $headers = "From: [email protected]" . "\r\n" .
                 "CC: [email protected]";

      $enviar = mail($para, $assunto, $msg, $headers);
      if($enviar){
         echo "E-mail enviado com sucesso";
         sleep(5);
      }else{
         echo "Erro";
      }
   }
}
    
20.12.2016 / 02:01