Futamiya Posted January 21, 2022 Share Posted January 21, 2022 Hello, localhost version PS : 1.7.8.2 The mail work. If you have a question for "how to send mail in localhost?" I can help. But my question it about a loop. I created a crm module. But I need to send mail when a ticket it is create. For example, when the salary will contact a customer in a specific datetime. So, I have a problem with my loop and with the date format. This is my function : public function my_function(){ $today = new DateTime('2022-02-01 09:09'); $mailtest = '[email protected]'; $sql = "SELECT " . _DB_PREFIX_ . "module.id, " . _DB_PREFIX_ . "module.mail, " . _DB_PREFIX_ . "module.alert, " . _DB_PREFIX_ . "module.commentaire, " . _DB_PREFIX_ . "module.datetime, " . _DB_PREFIX_ . "module.statut FROM `" . _DB_PREFIX_ . "module` WHERE id=" . (int)Tools::getValue('id_com'); $com = Db::getInstance()->ExecuteS($sql); foreach ($com as $row){ if($row['alert']==$today) { $alert = $row['alert']; $email = $row['mail']; $coment = $row['commentaire']; $date =$row['datetime']; $this->sendEmailAlert($alert,$email,$coment,$date); } } } Two question : I don't know how I can format my $row['alert'] and my $today format. date / today : 2022-01-21 17:43:30 alert : 2022-02-01T09:09 Doesn't match. And, where I can put my loop ? I want that is work even if I don't use my module 😕 Someone can I help me ? Please And if you need help about configuration about localhost send message. I can. See u Thanks Futamiya Link to comment Share on other sites More sharing options...
lordignus Posted January 22, 2022 Share Posted January 22, 2022 (edited) public function my_function(){ $today = new DateTime(); // if you want the current day (i.e. today) you don't need any arguments when instantiating a DateTime $today = $today->format('Y-m-d'); // will give a string in the format e.g. '2022-01-22' $mailtest = '[email protected]'; $sql = "SELECT " . _DB_PREFIX_ . "module.id, " . _DB_PREFIX_ . "module.mail, " . _DB_PREFIX_ . "module.alert, " . _DB_PREFIX_ . "module.commentaire, " . _DB_PREFIX_ . "module.datetime, " . _DB_PREFIX_ . "module.statut FROM `" . _DB_PREFIX_ . "module` WHERE id=" . (int)Tools::getValue('id_com'); $com = Db::getInstance()->ExecuteS($sql); foreach ($com as $row){ if(substr($row['alert'],0,10) == $today) { //compare the first 10 characters of the DB value (e.g. '2022-01-22') to the formatted DateTime. $alert = $row['alert']; $email = $row['mail']; $coment = $row['commentaire']; $date =$row['datetime']; $this->sendEmailAlert($alert,$email,$coment,$date); } } } See changes and comments above for matching date formats, hope that helps. Edited January 22, 2022 by lordignus Mistake (see edit history) Link to comment Share on other sites More sharing options...
Futamiya Posted January 24, 2022 Author Share Posted January 24, 2022 Thank you very much I will try it. But in the same time, Where and When I can put my loop ? Because, this is a module. And I want that, each second, the loop turn, to compare the $date_alert to the current date. And when They match : I want that the module send $mail_alert I don't know if I am clear about this, because I start to understand php, sql and so on. So, thank you very much for your help Have a good day Futamiya Link to comment Share on other sites More sharing options...
Futamiya Posted April 12, 2022 Author Share Posted April 12, 2022 Hello, I come back and that didn't work. I don't know what to do ? Sincerely Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now