ragrim Posted November 16, 2009 Share Posted November 16, 2009 Hi, I have a bit of a helpdesk project i have been working on and so far everything is going well, but i have finally hit a wall.... When created work orders i have a category drop down box, now when a work order is created i would like to send an email to the relevant technician letting them know a new work order is created. we have about 10 categories and 3 technicians. id be happy to hard code it if i need to but ultimately id like some super cool script that does a whole heap of if statements. So here is basically what im after, and i have no idea how to do it as i havnt done many if statements... mysql_query(insert into workorders values summary, category, etc) if category = 1 send email to technician 1 if category = 2 send email to technician 2 if category = 3 send email to all technicians im not sure where to start on this so any help would be appreciated, thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/181793-send-email-based-on-category-selected/ Share on other sites More sharing options...
MadTechie Posted November 17, 2009 Share Posted November 17, 2009 The trick behind this is to create a table in the database that had the technician # emails, ie ID, Name, email 1, technician 1, tech1@email.com 2, technician 2, tech2@email.com 3, technician 3, tech3@email.com then in the form loop thought the list and create select option for each technician in the form, ie <SELECT name="tech"> <OPTION VALUE="0">All</OPTION> <?php $result = mysql_query("SELECT * FROM table"); while($row = mysql_fetch_assoc($result)){ ?> <OPTION VALUE="<?php echo $row['ID']; ?>"><?php echo $row['Name']; ?></OPTION> <?php } ?> </SELECT> then in the email script have $tech = (int)$_POST['tech']; //get requested email id if($tech > 0){ $result = mysql_query("SELECT * FROM table WHERE ID=$tech"); }else{ $result = mysql_query("SELECT * FROM table"); } $emails = array(); while($row = mysql_fetch_assoc($result)){ $emails[] = $row['Email']; //build email list } $emails = implode(",",$emails); //put emails into a comma delimited string echo "email to ".$emails; please note all code was written direct so theirs probably typos/syntax errors, but it should give you the idea Quote Link to comment https://forums.phpfreaks.com/topic/181793-send-email-based-on-category-selected/#findComment-958826 Share on other sites More sharing options...
ragrim Posted November 17, 2009 Author Share Posted November 17, 2009 Thats a good start thanks.. Gives me an idea of what to do, ill have a play and report back when it doesnt work lol. Quote Link to comment https://forums.phpfreaks.com/topic/181793-send-email-based-on-category-selected/#findComment-958828 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.