This topic is locked

Mail to list by table value

10/22/2006 12:55:29 PM
PHPRunner General questions
G
gdude66 author

Hi,

I have a project where there is an add activity option from a table called activity.

In another table (staff) are a list of people with group number eg 1, 2, 3, 4 based onpermission level and they each have an email address in that table.
If an event is added I would like to use the send mail option and send it to all email addresses to say group 4. Is there an easy way to do this in the before record added option?

I would like all people at group level 4 to get this email.

Thanks

J
Jane 10/23/2006

Graeme,
Sure you can do it using BeforeAdd event.

Here is a sample code:

function BeforeAdd(&$values)

{

$email="";

$message="";

$subject="New data record";
foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";
global $conn;

$str = "select * from users where GroupID='".$_SESSION["GroupID"]."'";

$rs = db_query($str,$conn);
while($data = db_fetch_array($rs))

{

mail($data["email"], $subject, $message);

}

return true;

}



where email is your actual field name.

G
gdude66 author 10/24/2006

Graeme,

Sure you can do it using BeforeAdd event.

Here is a sample code:
where email is your actual field name.



Thanks Jane.

So I presume that I put say 1 for group 1 in the GROUPID tag or how do I ensure that email is sent to all members of group 1?

Sorry but I am a bit slow on this.

J
Jane 10/24/2006

Graeme,
if you want to send emails to all users of entered GroupID (GroupID is filled on the ADD page) change this code in the following way:

function BeforeAdd(&$values)

{

$email="";

$message="";

$subject="New data record";
foreach($values as $field=>$value)

$message.= $field." : ".$value."\r\n";
global $conn;

$str = "select * from users where GroupID='".$values["GROUPID"]."'";

$rs = db_query($str,$conn);
while($data = db_fetch_array($rs))

{

mail($data["email"], $subject, $message);

}

return true;

}

G
gdude66 author 10/24/2006

Graeme,

if you want to send emails to all users of entered GroupID (GroupID is filled on the ADD page) change this code in the following way:



Thanks

G
gdude66 author 10/28/2006

OK thanks I think I have a handle on that.
So I have 3 tables with staff details, event type and student details.
If I take this to the next level and use a third table where I have students each split into 3 levels. Say J, M, S and I want email about new events of students in J to go to staff from group 1 only and emails about events of students in M to staff from group 2 only and emails about events of students in group S to go to staff in group 3 only then what would I add to accomplish that?

I know it is complicated but this is the last thing I need to complete the project in this format (until the next thing).

Alexey admin 10/30/2006

Graeme,
this task requires some custom programming.

You can try to do this yourself or hire a programmer.
You need to know PHP to implement this yourself.

Here are some good links to start learning PHP.
http://www.w3schools.com/php/default.asp

http://www.webcheatsheet.com

http://www.php.net