Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/181793-send-email-based-on-category-selected/
Share on other sites

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

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.