Send email after a change in the database

0

Hello, I'm using the MySQL database and I have an event that runs daily at 1 hour. Within this event I check the date present in a row and compare with the current date, if the current date is smaller then I make the necessary operations. The problem is that I need to send an email indicating that this operation has occurred. Is it possible to call a PHP function to perform this work from the MySQL event?

    function daily_situation_update()
   {
    global $wpdb;
    $mapping = get_option('socialdb_general_mapping_collection');
    $collection_id = $mapping['Emprestimo'];
    $event = "CREATE 
        EVENT IF NOT EXISTS
         e_daily_situation_update
        ON SCHEDULE
          EVERY 1 DAY_HOUR 
        COMMENT 'Altera o Status dos livros'
        DO
          BEGIN 
            SET SQL_SAFE_UPDATES = 0;
            UPDATE
                $wpdb->term_relationships
            SET
                term_taxonomy_id = ...
    
asked by anonymous 06.06.2017 / 19:08

1 answer

0

I believe that you can send us an email:                        Sending Email via PHP        

   <body>

      <?php
         $to = "[email protected]";
         $subject = "Assunto do Email";

         $message = "<b>Mensagem HTML</b>";

         $header = "From:[email protected] \r\n";
         $header .= "Cc:[email protected] \r\n";
         $header .= "MIME-Version: 1.0\r\n";
         $header .= "Content-type: text/html\r\n";

         $retval = mail ($to,$subject,$message,$header);

         if( $retval == true ) {
            echo "Sucesso...";
         }else {
            echo "Algo deu errado...";
         }
      ?>

   </body>
</html>

Reference: Example Source

    
06.06.2017 / 20:29