Jump to content

Archived

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

k4pil

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

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!

Share this post


Link to post
Share on other sites
cant really do it that way, why cant you add the email script to the page where the data is entered. eg
if priority = high then email... simple!

Share this post


Link to post
Share on other sites
Ok,...but i have no idea of how to do it that way either...where do i start???

Can you give me some help on what i need to do something like that
??

Share this post


Link to post
Share on other sites
Just when you are inserting the information into the database add a chunk of code that sends an email below it.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sooo simple...but soo effective.

Ive been trying triggers, emailing scripts...u name it..lol

Thanks pps for showing me the light

**SOLVED**

Share this post


Link to post
Share on other sites

×

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.