E-mail after a change in the database

Asked

Viewed 44 times

0

Hello, I am using Mysql database and 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 lower then I do the necessary operations. The problem is that I need to send an email indicating that this operation has taken place. It is 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 = ...
  • How are you performing this daily task? Cron?

  • I created an event in Mysql to perform this task, created the event from PHP

  • So please [Edit] the question and add these codes. If you already have PHP involved in this process, it should not be difficult to make it send the email.

1 answer

0

I believe that with this you can send 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

  • The problem is not sending an email using PHP, but sending this email only when the Mysql event makes changes in a particular column.

  • I believe you can do an 'if' to validate the $Event variable, if it is the expected result = send the email, if it is not, process it the way you want ... Something in this sense.

Browser other questions tagged

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