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!
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.