Jump to content

Anyone know how to use triggers to send emails???


k4pil

Recommended Posts


Hi there ppl!

I think this question maybe a lil complex.

I want to create a trigger in my mySql database which sends an email upon an event.

I have a table case(caseID, custID, priority, subject, description, type, created, solved )
When a new row is added which has priority = "high" i want the database to send an email to all the users from another table in the database;
staff( userID, staff, access, username, password, name, surname, email )
where access = "3". Email address is also recorded in this table.

I have no idea how to do this.

Anyone??

Thanks in advance as always!
Ya, if the data you are about to enter in the DB meets those qualifications you listed above, pull everyone out of the table staff that has an access level of >= 3, and then mail that.

[code]
$query = mysql_query("SELECT * FROM `staff` WHERE `access` >= '3'");

if(mysql_num_rows($query) >= 1) {

  $sendto = "";

   while($r = mysql_fetch_array($query)  ) {

     if($sendto) {
        $sendto .= ",{$r['email']}";
     } else {
        $sendto = $r['email'];
     }
   }

   //send the email
   mail($sendto, $subject, $body, "From: youremail@domain");
}
[/code]

Something along those lines would do the trick.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.