Hello there; this is my first post here, so be gentle grin
Seriously though; I have a script that is run via a scheduled task on a machine I leave running all the time. The script runs once a day; and is used to list a group of people that are "incoming" as new employees within a 10 day period.
The script runs perfectly; in fact I even managed to FINALLY figure out how to get it to place ALL incoming employees in ONE email instead of sending one per employee...HOWEVER, what I can't seem to sort out is how to get it to send ONLY if the result set is TRUE.
If there ARE NO employees in the upcoming 10 days; I do NOT want all those on the list receiving a blank email...
OR; an if/else type setup with alternate text for zero results would be fine; but that won't work either...
The clincher is that it HAS to remain a one-email process...there are 7 people receiving it, and they don't want to go back to getting one email per incoming employee (we have a lot of incoming emps this time of year)...
Heres the code; anyone have any thoughts?
<?php
//email to notify ALL involved personell of any incoming employees in the upcoming 10 days
$db = mysql_connect("localhost", "root", "");
mysql_select_db("dbname", $db);
$result = mysql_query("select * from list where date < DATE_ADD(NOW(), INTERVAL 10 DAY) and date >= NOW() AND status = 'Not Complete'",$db);
while ($myrow = mysql_fetch_row($result)) {
$message = $message."$myrow[14]\$myrow[10] $myrow[11]\$myrow[12] $myrow[13]\$myrow[9]\: $myrow[4]\n $myrow[8]\n\n\n";
}
//verify output on page for webmaster purposes ONLY
echo"<pre>";
print_r($message);
echo"</pre>";
//send message
mail("me@myjob.com", "Incoming Employees(10 days in advance)", $message,
"From: LCDB\r\n"
."Reply-To: [email]me@myjob.com[/email]\r\n"
."X-Mailer: PHP/" .phpversion());
//error if not sent
if(!$message){
echo "Email not sent! Please try later...";
}else{
echo "Mail sent successfully!";
}
?>
What can I add/change to either keep it from sending empty emails or to get it to add "No incoming employees" or something to the email text, if it INSISTS on sending, either way..?
Any and all thoughts appreciated! Thanks!