Hello,
The entire hook "incident after insert" is included here. The array code has been commented out for testing of the new code you have suggested. The array works fine, but I want to be able to allow the end user to specify the email addresses so that I don't have to go into the hooks and update it every time they want a change in recipients. I created a table in the database called 'eaddress' which has a row called 'email_address'.
As it is now with the code below, there is no error message or indications in the PHP editor of something wrong, but when the form is submitted no email is sent.
As I may have mentioned in prior posts, I'm very new and green at PHP. Anything outside the very basics stumps me at this point. But, I've made headway in some understanding thanks to the help of this forum.
Thank you for your time.
Ray
Code: Select all
function incident_after_insert($data, $memberInfo, &$args){
// to compose a message containing the submitted data,
// we need to iterate through the $data array
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
$authName = sqlValue("select custom1 from membership_users where memberID='{$memberInfo['username']}'");
$projectname = sqlValue("select name from project where id='{$data['project']}'");
$receipt =sqlValue("SELECT email_address FROM eaddress");
while ($row = db_fetch_assoc($receipt )) {
$receipt = $row['email_address'];
}
/*$receipt=array('[email protected]',[email protected]);*/
$msgTEXT = "The following Incident Report was submitted by $authName.<br> This is a preliminary report, details may change."."
<p><strong>Project: </strong>$projectname
<p><strong>Date of incident: </strong>{$data['date']}
<p><strong>Time of incident: </strong>{$data['time']}
<p><strong>Type of Incident: </strong>{$data['type']}
<p><strong>Incident Summary: </strong>{$data['summary']}
<p><strong>How did it happen: </strong>{$data['how']}
<p><strong>Objects involved: </strong>{$data['object']}
<p><strong>What were people doing: </strong>{$data['activity']}
<p><strong>Comments: </strong>{$data['comments']}
<p><strong>Witnesses: </strong>{$data['witness']}
<p><strong>Behavior Based Safety Factor: </strong>{$data['bbs']}";
foreach ($receipt as $address){
sendmail(array(
// mail recipient
'to' => $address,
'name' => "",
// subject
'subject' => "An incident report has been submitted for " . sqlValue("select name from project where id='{$data['project']}'"),
// message
'message' => nl2br (stripcslashes($msgTEXT)),
// sender address
"From: [email protected]"
));
}
//end email code
return TRUE;
}