I want to send an email only if the field name 'Active' has changed in my database table bus_status..
It is a boolean field (TRUE or FALSE) so if it is False and changes to TRUE upon update I want it to send the email or if is TRUE and it is changed to false on update then I want it to send the email.

This code was placed into a HOOK file that has a function started called After_Update which is triggered after the record is changed.

If I just remove the first two lines of this code it will send the email when the entire record is modified at all.. But that is too many emails.. I only want to send the email when the Active field is changed which is critical for limiting the notifications.

Any Suggestions? I tried this below with no luck:

if(isset ($_POST{$data['Active']}));
{
@mail(
// mail recipient
"user@domain.com, 2ndUser@domain.com",

// subject
"A Driver's ACTIVE STATUS HAS CHANGED - notification - Driver RECORD NUMBER-{$data['Record_Id']}",

// message
      "The above record {$data['Record_Id']} was just modified with the driver's Active Status changing from FALSE to TRUE or True to FALSE, by:{$memberInfo['username']} The record was updated on and by:{$data['LastUpdatedby']} \n To view the record please go to \n http://bigschoolbus.com/asdata2/compliance_view.php?SelectedID=".$data['selectedID']."  Newly entered data shows as actual table values below:,
     {$messageData2} \n.  The user that changed this record did so from IP Address: {$memberInfo['IP']}  \n\n", 

// sender address
"user@domain.com"
);
 }


return TRUE;
    }
Member Avatar for iamthwee

You need to save somewhere in your db the previous field state. If it has changed then send an email.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.