Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 k4pil

k4pil
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 09 March 2006 - 06:59 PM


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!

#2 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 09 March 2006 - 09:07 PM

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!
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#3 k4pil

k4pil
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 09 March 2006 - 11:38 PM

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
??

#4 Gaia

Gaia
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationCanada

Posted 09 March 2006 - 11:43 PM

Just when you are inserting the information into the database add a chunk of code that sends an email below it.

#5 Flinch

Flinch
  • Members
  • PipPip
  • Member
  • 13 posts
  • Locationcomputer, house, USA

Posted 09 March 2006 - 11:51 PM

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.

$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");
}

Something along those lines would do the trick.
[br][br][br][br]

#6 k4pil

k4pil
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 10 March 2006 - 11:58 AM

Sooo simple...but soo effective.

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

Thanks pps for showing me the light

**SOLVED**




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users