This topic is locked

Complex Email Requirement

2/2/2008 2:11:22 AM
PHPRunner General questions
S
smcgo4 author

Hi - using PHPRunner 4.1 Build 320 and MySQL as the db back end. In a school situation. Behaviour recording database. Information is added to the incidents table. This table has lookups for the class teacher id (staff table, containing their email addess). What I want to be able to do is send an email to me when an incident is added (got this part worked out) and also an email to the class teacher when and incident is added. At the moment I am using the Before Record Added event. My question, is it possible to 'lookup' the email address from the staff table and then use it for the mail function as well? This is the SQL I am using to generate the incidents data:
select `Id`,

`IncidentDateandTime`,

`IncidentLocationCode`,

`Behaviour`,

`StudentID`,

`StaffID`,

`TeacherID`,

`IncidentDetails`,

`SuggestedAction`

From `incidents`
Thanks
Steve

A
alang 2/2/2008

Certainly - in the same event code execute an SQL statement on your staff table and use the email address returned as the recipient of a second email.
ie "SELECT * from staff WHERE `StaffID` = '".$values["StaffID"]."'"
Assuming StaffID is also the name of the key field in your staff table.

J
Jane 2/4/2008

Steve,
to select email from another table use this sample code:

$conn;

$str = "select Email from TableName where TeacherID=".$values["TeacherID"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
$email = $data["Email"];



where Email and TeacherID are your actual field names in the TableName table.

S
smcgo4 author 2/4/2008

Hi Jane
Thank you for your help. Are there some missing quotes in this code snippet? I got an error that the .$values["TeacherID"]; was being treated as a table column rather than a value. Managed to get that part working by changing to

$str = "SELECT Email from staff WHERE `StaffID` = '".$values["StaffID"]."'"; (thank you AlanG).
The next stumbling block appears to be the $email = $data["Email"]; line, I get an
2 Error description mail() [function.mail]: Could not execute mail delivery program '/usr/sbin/sendmail -t -i ' error.
Is this because the email address is not being passed as a quoted string?
Cheers

Steve,

to select email from another table use this sample code:
where Email and TeacherID are your actual field names in the TableName table.

L
laonian 2/4/2008

You may try this one.
$email = "".$data["Email"]."";

S
smcgo4 author 2/4/2008

Works like a charm! You guys and gals are fantastic. People are going to think I am so clever! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=25538&image=1&table=forumreplies' class='bbc_emoticon' alt=':lol:' />