SELECT user by Date

Asked

Viewed 44 times

1

I have a Select mysql searching my clients by taking the name, email by date of day...

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

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

Grateful!!

  • You can select all, and give a while sending the emails or if the content of the emails is the same for all you can make an array with the emails and send to all in one send only, it is not easier?

1 answer

1


Come on, since you didn’t specify the average amount of emails I’ll create a simple example of how to do this:

I’ll use PDO for the appointments, 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";
      }
   }
}
  • Hello Leo Letto, by email I have no way to search only by date, because I will select by date the email of the customer who signed up on that date.. can give an example for sending each one?

  • In this case use only select based on the date of execution of the script, is that your doubt, select by day?

  • I want to pick up the customer’s email via Where $data_today, and send one by one...

  • Do you have experience with PHP Mailer? For bulk shipments it is more recommended, you may end up soiling your domain name by sending many emails the right settings

  • Leo Letto, I use the function mail(), I already know how to send, I will send inside While, but missing pick one by one to do the sending, will be few submissions.. I have it... but it’s not working... $query= $Conn->prepare("SELECT EMAIL FROM usuarios ORDER WHERE data_cad='$data_hj'); $query->execute(); while($line = $query->fetch(PDO::FETCH_ASSOC)) { $email = $line['EMAIL']; }

  • Inside while, it will already go through each of the records returned by mysql search, just send the email inside while it will go to all one by one

  • Exactly this, just not working as I did... Can you give me an example? E How do I give an ECHO and see each E-mail printed on the screen, for me to test..

  • I put an example see if it’s what you need

  • I got it here... Valeuu

  • I put a Sleep() of 5 seconds to give a rest between the shipments, feel free to take if you want.

  • Thanks @Leo Letto

Show 6 more comments

Browser other questions tagged

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