I have a script I use to notify (email) course directors if they have a waiting question in a queue.
The problem is I now need to ensure that if there are multiple course directors then they both get an email and either can reply.
Here is the email function.
function notify($cid) {
global $db;
$CONF_PATH = $_SERVER['DOCUMENT_ROOT'];
$sql = $db->sql_query("SELECT * FROM comment_queue cq JOIN director d
ON d.course_id = cq.course_id
WHERE cid = '$cid'");
if (!$sql) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
while ($row = $db->sql_fetchrow($sql)) {
$to = $row['email'];
$title = $row['title'];
$lastname = $row['last_name'];
$message = $row['comment_text'];
$headers .= "From: do_not_reply\nReply-To: do_not_reply@wright.edu \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$subject = "Muddy Water has a question waiting";
$link = 'http://www.idtltest.wright.edu/muddy/admin/login.php';
// Get the welcome email body from saved .html file
if(!$fp = fopen($CONF_PATH."/muddy/template/emailquestion.tpl", "r")) {
//file open failed, create error routine here
Print ("File open failed very badly!");
exit;
}
while (!feof($fp))
{
$send_body .= fgets($fp, 100);
}
fclose($fp);
$send_body = eregi_replace("__lastname__", $lastname, $send_body);
$send_body = eregi_replace("__title__", $title, $send_body);
$send_body = eregi_replace("__message__", $message, $send_body);
$send_body = eregi_replace("__link__", $link, $send_body);
//echo"$send_body";
mail($to, $subject, $send_body, $headers);
}
}
It uses a template.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Muddy Water Questions</title>
</head>
<body>
<div align="center" style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 20px; color: red;">
Question Waiting for Muddy Waters.
<hr>
</div>
<br>
<div style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px;" Style:font-color="red">
Professor __lastname__, <br>
<br>
A student has submitted a question to the Muddy Waters system and is waiting your reply. If you have any questions, please email the Curriculum IT Support developer at: <a href="mailto:steven.donovan@wright.edu">steven.donovan@wright.edu</a><br>
<table width="100%">
<tr><td>The title of the question is: __title__ </td></tr>
<br><br>
<tr><td>The contents of the question is: <quote> __message__ </quote></td></tr>
<br><br><br>
<tr><td>Click on the following link to go to the Muddy Waters system and sign in with your "W" Account login and password.</td></tr>
<br>
<tr><td>__link__</td></tr>
</table>
<br><br>
Thank you for your support of the Muddy Waters system!
<br>
SOM Curriculum IT Support Staff<br>
</div>
</body>
</html>
For course_id=1, I had two course directors and when I submitted a question for that course both directors received the email, however director_id=3 got an email with both sets of information displayed. director_id 1 and themsleves director_id=3
You can imagine what it looks like from the template.
Professor Smith,
blah blah
etc
etc
Thank You
Professor Jones,
blah blah
etc
etc
Thank You
director_id=1 got their email which displayed properly with only the information for that director.
What I need is a loop to properly send the right information to each director.
Any ideas?