I am taking over a website that was compromised. I am getting error messages when trying to run a cron job to send out mail messages. Additionally I think the PHP script looks rather odd. It was written by another person, Any Help would be appreciated. I have not done this in a long time.
Here is the code
<?php #!/usr/local/bin/php -q ?>
<?php require_once('../Connections/clientsConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
function RandomWordByInterval($TimeBase, $QuotesArray){
// Make sure it is a integer
$TimeBase = intval($TimeBase);
// How many items are in the array?
$ItemCount = count($QuotesArray);
// By using the modulus operator we get a pseudo
// random index position that is between zero and the
// maximal value (ItemCount)
$RandomIndexPos = ($TimeBase % $ItemCount);
// Now return the random array element
return $QuotesArray[$RandomIndexPos];
}
// Use the day of the year to get a daily changing
// quote changing (z = 0 till 365)
$DayOfTheYear = date('z');
// You could also use:
// --> date('m'); // Quote changes every month
// --> date('h'); // Quote changes every hour
// --> date('i'); // Quote changes every minute
// Example array with some random quotes
$RandomWords = array(
'Leash: A strap that attaches to your collar, enabling you to lead your owner where you want him or her to go. Make sure that you are waiting patiently with leash in mouth when your owner comes home from work. This immediatly makes your owner feel guilty and the walk is lengthened by a good 10 minutes. ',
'Dog Bed: Any soft, clean surface, such as a white bedspread, newly upholstered couch or the dry cleaning that was just picked up. ',
'Drool: What you do when your owners have food and you don\'t.To do this properly, sit as close as you can, look sad and let the drool fall to the floor or better yet on their laps. ',
'Sniff: A social custom to use when you greet other dogs or those people that sometimes smell like dogs. ',
'Garbage Can: A container your neighbors put out weekly to test your ingenuity.Stand on your hind legs and push the lid off with your nose. If you do it right, you are rewarded with food wrappers to shred, beef bones to consume, moldy crusts of bread and sometimes even an old Nike. ',
'Bicycles: Two-wheeled exercise machines, invented for dogs to control body fat. To get maximum aerobic benefit, you must hide behind a bush and dash out, bark loudly and run alongside for a few yards. The rider swerves and falls into the bushes, and you prance away. ',
'Thunder: A signal the world is coming to an end. Humans remain amazingly calm during thunderstorms, so it is necessary to warn them of the danger by trembling, panting, rolling your eyes wildly and following at their heels. ',
'Wastebasket: A dog toy filled with paper, envelopes and old candy wrappers. When you get bored, turn over the basket and strew the papers all over the house. This is particularly fun to do when there are guests for dinner and you prance around with the contents of that very special bathroom wastepaper basket! ',
'Sofas: Are to dogs like napkins are to people. After eating it is polite to run up and down the front of the sofa and wipe your whiskers clean. If there are people sitting on the couch just include them as a handy wipe. ',
'Bath: A process owners use to clean you, drench the floor, walls and themselves. You can help by shaking vigorously and frequently. ',
'Lean: Every good dog\'s response to the command "sit," especially if your owner is dressed for an evening out. Incredibly effective before black-tie events.',
'Love: A feeling of intense affection, given freely and without restriction, shared by you and your owner. Show it by wagging your tail'
);
$wordoftheday = RandomWordByInterval($DayOfTheYear, $RandomWords);
mysql_select_db($database_clientsConn, $clientsConn);
$query_groomingdue_RS = "SELECT * FROM clients WHERE email != '' and client_id not in (select client_id from appointments where appt_date > subdate(curdate(),INTERVAL 6 WEEK)) and date_emailed = 'False'";
$groomingdue_RS = mysql_query($query_groomingdue_RS, $clientsConn) or die(mysql_error());
$row_groomingdue_RS = mysql_fetch_assoc($groomingdue_RS);
$totalRows_groomingdue_RS = mysql_num_rows($groomingdue_RS);
$query_groomingtomorrow_RS = "SELECT * FROM clients WHERE email != '' and client_id in (select client_id from appointments where appt_date = adddate(curdate(),INTERVAL 1 DAY))";
$groomingtomorrow_RS = mysql_query($query_groomingtomorrow_RS, $clientsConn) or die(mysql_error());
$row_groomingtomorrow_RS = mysql_fetch_assoc($groomingtomorrow_RS);
$totalRows_groomingtomorrow_RS = mysql_num_rows($groomingtomorrow_RS);
do {
//BEGIN SENDING E-MAILS LOOP WITH 1 SEC INTERVALS
########check to see if customer is eligible for $5 coupon
$query_couponcheck_RS = sprintf("SELECT * from credits where email = %s",
GetSQLValueString($row_groomingdue_RS['email'],"text"));
$couponcheck_RS = mysql_query($query_couponcheck_RS, $clientsConn) or die(mysql_error());
$totalRows_couponcheck_RS = mysql_num_rows($couponcheck_RS);
if ($totalRows_couponcheck_RS == 0) $offer = "\r\r *You also qualify for $5.00 off your next full grooming when you schedule online! (Limit one coupon per pet owner)* \r";
elseif($totalRows_couponcheck_RS > 0) $offer = '';
##########
$to = $row_groomingdue_RS['email'];
$subject = $row_groomingdue_RS['pet_name']." is due for a grooming!";
$message = " Dear ".$row_groomingdue_RS['pet_name'].",\r\r We know you like to look your best, smell your sweetest, and feel great! So please let your best friend know it's time for your next professional grooming at noras grooming. You can schedule your appointment online at http://www.norasgrooming.com or give us a call at (999) 999-9999. \r\r Thank You,\r noras grooming".$offer."\r\r Word Of The Day (Defined By A Dog)\r \"".$wordoftheday."\"";
$from = "
[email protected]";
$headers = "From: $from";
mail($to,$subject,$message,$headers) or die("MAIL ERROR");
$query_update_date_emailed = sprintf("UPDATE clients SET date_emailed = CURDATE() where client_id = %s",
GetSQLValueString($row_groomingdue_RS['client_id'],"text"));
$exe_update_date_emailed = mysql_query($query_update_date_emailed, $clientsConn) or die(mysql_error());
sleep(1);
}
while ($row_groomingdue_RS = mysql_fetch_assoc($groomingdue_RS));
do {
//BEGIN SENDING E-MAILS LOOP WITH 1 SEC INTERVALS FOR NEXT DAY REMINDERS /////////////////////////////////////////////////////////////////////////////
########check to see if customer is eligible for $5 coupon
$to = $row_groomingtomorrow_RS['email'];
$subject = $row_groomingtomorrow_RS['pet_name']."'s grooming is tomorrow!";
$message = " Dear ".$row_groomingtomorrow_RS['pet_name'].",\r\r This is just a friendly reminder that your grooming at Nora's is tomorrow. If there has been a change and you need to reschedule, please call us at (999)999-9999 A.S.A.P. \r\r Thank You,\r noras grooming \r\r Word Of The Day (Defined By A Dog)\r \"".$wordoftheday."\"";
$from = "
[email protected]";
$headers = "From: $from";
mail($to,$subject,$message,$headers) or die("MAIL ERROR");
sleep(1);
}
while ($row_groomingtomorrow_RS = mysql_fetch_assoc($groomingtomorrow_RS));
?>
Untitled Document
<?php
mysql_free_result($groomingdue_RS);
mysql_free_result($groomingtomorrow_RS);
?>